:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-muted: #f8f9fa;
  --text: #202429;
  --text-soft: #687078;
  --line: #e1e4e8;
  --line-strong: #cdd2d8;
  --primary: #176f4d;
  --primary-hover: #115c3f;
  --primary-soft: #e9f5ef;
  --accent: #2869b3;
  --accent-soft: #eaf2fb;
  --danger: #b4232f;
  --danger-hover: #961c27;
  --danger-soft: #fbeaec;
  --warning: #8a5900;
  --warning-soft: #fff5dc;
  --sidebar: #22272b;
  --sidebar-soft: #31373c;
  --shadow: 0 8px 24px rgba(25, 32, 38, 0.08);
  --radius: 8px;
  --sidebar-width: 240px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(40, 105, 179, 0.2);
  outline-offset: 1px;
}

.app-shell {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  z-index: 30;
  inset: 0 auto 0 0;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  padding: 22px 16px 18px;
  color: #f5f7f8;
  background: var(--sidebar);
}

.brand {
  display: flex;
  align-items: center;
  min-height: 44px;
  gap: 11px;
  padding: 0 8px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  object-fit: contain;
}

.brand strong {
  display: block;
  font-size: 14px;
  font-weight: 650;
}

.nav-list {
  display: grid;
  gap: 5px;
  margin-top: 31px;
}

.nav-item {
  min-height: 42px;
  padding: 0 13px;
  border: 0;
  border-radius: 6px;
  color: #c3c9ce;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.nav-item:hover {
  color: #ffffff;
  background: var(--sidebar-soft);
}

.nav-item.active {
  color: #ffffff;
  background: #3a4146;
  box-shadow: inset 3px 0 var(--primary);
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid #3c4247;
  padding: 17px 5px 0;
}

.connection-state {
  display: flex;
  align-items: center;
  min-height: 28px;
  gap: 8px;
  margin-bottom: 10px;
  color: #b7bec3;
  font-size: 12px;
}

.connection-state i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #81898f;
}

.connection-state.connected i {
  background: #42ba83;
  box-shadow: 0 0 0 3px rgba(66, 186, 131, 0.14);
}

.connection-state.failed i {
  background: #ef6a73;
}

.main {
  min-height: 100vh;
  margin-left: var(--sidebar-width);
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  min-height: 78px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 13px 30px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 246, 248, 0.96);
  backdrop-filter: blur(8px);
}

.topbar h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.25;
}

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

.last-refresh {
  color: var(--text-soft);
  font-size: 12px;
}

.mobile-menu {
  display: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
}

.content {
  width: min(100%, 1480px);
  margin: 0 auto;
  padding: 27px 30px 46px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-heading {
  display: flex;
  min-height: 52px;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.section-heading h2,
.panel-title h3 {
  margin: 0;
  font-size: 17px;
  line-height: 1.4;
}

.section-heading p,
.panel-title p {
  margin: 4px 0 0;
  color: var(--text-soft);
  font-size: 12px;
}

.heading-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 9px;
}

.button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

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

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

.button.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.button.secondary {
  border-color: var(--line-strong);
  color: #343a40;
  background: var(--surface);
}

.button.secondary:hover:not(:disabled) {
  border-color: #aeb5bb;
  background: var(--surface-muted);
}

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

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

.button.ghost {
  border-color: #4b5359;
  color: #e8ebed;
  background: transparent;
}

.button.ghost:hover {
  background: var(--sidebar-soft);
}

.button.small {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 12px;
}

.button.full {
  width: 100%;
}

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

.stat-card {
  min-height: 112px;
  padding: 19px;
  border: 1px solid var(--line);
  border-top: 3px solid #8b949c;
  border-radius: var(--radius);
  background: var(--surface);
}

.stat-card.positive {
  border-top-color: var(--primary);
}

.stat-card.accent {
  border-top-color: var(--accent);
}

.stat-card span,
.stat-card strong {
  display: block;
}

.stat-card span {
  color: var(--text-soft);
  font-size: 12px;
}

.stat-card strong {
  margin-top: 8px;
  font-size: 29px;
  line-height: 1.2;
}

.panel-grid,
.maintenance-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 1fr);
  gap: 16px;
}

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

.panel {
  padding: 20px;
}

.api-guide {
  margin-top: 16px;
  padding: 0;
  overflow: hidden;
}

.api-guide summary {
  padding: 16px 20px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 650;
}

.api-guide[open] summary {
  border-bottom: 1px solid var(--line);
}

.api-guide-content {
  display: grid;
  gap: 15px;
  padding: 18px 20px 20px;
}

.api-guide-content p,
.api-example h3,
.api-example pre {
  margin: 0;
}

.api-guide-content > p:not(.privacy-note) {
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.65;
}

.api-example {
  display: grid;
  gap: 7px;
}

.api-example h3 {
  font-size: 12px;
}

.api-example pre {
  overflow-x: auto;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
}

.api-example code {
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre;
}

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

.status-bars {
  display: grid;
  gap: 12px;
}

.status-row {
  display: grid;
  grid-template-columns: 68px minmax(80px, 1fr) 45px;
  align-items: center;
  gap: 11px;
}

.status-row > span {
  color: var(--text-soft);
  font-size: 12px;
}

.status-row > strong {
  text-align: right;
  font-size: 12px;
}

.bar-track {
  height: 7px;
  overflow: hidden;
  border-radius: 4px;
  background: #edf0f2;
}

.bar-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.status-row[data-status="checking"] .bar-track i,
.status-row[data-status="leased"] .bar-track i {
  background: var(--accent);
}

.status-row[data-status="quarantine"] .bar-track i,
.status-row[data-status="cooldown"] .bar-track i {
  background: #b37a16;
}

.status-row[data-status="maintenance"] .bar-track i {
  background: #886fb1;
}

.status-row[data-status="invalid"] .bar-track i,
.status-row[data-status="expired"] .bar-track i {
  background: #b75a61;
}

.empty-inline,
.empty-cell {
  color: var(--text-soft);
  text-align: center;
}

.empty-inline {
  display: grid;
  min-height: 150px;
  place-items: center;
  font-size: 12px;
}

.empty-cell {
  height: 170px;
}

.quick-actions {
  display: grid;
  gap: 9px;
}

.quick-action {
  min-height: 48px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.quick-action:hover {
  border-color: #aeb8b2;
  background: var(--primary-soft);
}

.quick-action strong {
  display: block;
  font-size: 13px;
}

.filter-bar {
  display: grid;
  grid-template-columns: minmax(210px, 1.5fr) repeat(3, minmax(120px, 0.65fr)) auto;
  align-items: end;
  gap: 10px;
  margin-bottom: 13px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.filter-bar.compact {
  grid-template-columns: minmax(140px, 210px) auto;
  justify-content: start;
}

label {
  display: grid;
  gap: 6px;
  color: #444b51;
  font-size: 12px;
  font-weight: 600;
}

label small {
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 400;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--text);
  background: #ffffff;
}

input,
select {
  min-height: 38px;
  padding: 7px 10px;
}

textarea {
  min-height: 130px;
  padding: 10px;
  resize: vertical;
  font-family: Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
}

input::placeholder,
textarea::placeholder {
  color: #a0a7ad;
}

.table-panel {
  overflow: hidden;
}

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

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

th,
td {
  height: 49px;
  padding: 9px 14px;
  border-bottom: 1px solid #eceef0;
  text-align: left;
  vertical-align: middle;
}

th {
  height: 43px;
  color: #6d747b;
  background: var(--surface-muted);
  font-size: 11px;
  font-weight: 650;
}

td {
  font-size: 12px;
}

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

tbody tr:hover:not(:has(.empty-cell)) {
  background: #fbfcfc;
}

.cell-muted {
  color: var(--text-soft);
}

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

.badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 3px 8px;
  border-radius: 4px;
  color: #475058;
  background: #edf0f2;
  font-size: 11px;
  font-weight: 600;
}

.badge.available,
.badge.active,
.badge.enabled {
  color: #11613f;
  background: var(--primary-soft);
}

.badge.checking,
.badge.leased {
  color: #245c99;
  background: var(--accent-soft);
}

.badge.quarantine,
.badge.cooldown {
  color: #805300;
  background: var(--warning-soft);
}

.badge.maintenance {
  color: #674c90;
  background: #f1ecf8;
}

.badge.invalid,
.badge.expired,
.badge.revoked,
.badge.disabled {
  color: #9c2530;
  background: var(--danger-soft);
}

.pagination {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  color: var(--text-soft);
  font-size: 12px;
}

.pagination > div {
  display: flex;
  align-items: center;
  gap: 9px;
}

.maintenance-layout {
  grid-template-columns: minmax(280px, 0.85fr) minmax(340px, 1.15fr);
}

.keeper-flow {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.keeper-step {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  min-height: 78px;
  align-items: center;
  gap: 11px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.keeper-step.active {
  border-color: #a6cfbd;
  background: var(--primary-soft);
}

.step-number {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 50%;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 13px;
  font-weight: 700;
}

.keeper-step.active .step-number {
  color: #ffffff;
  background: var(--primary);
}

.keeper-step div {
  min-width: 0;
}

.keeper-step div > strong,
.keeper-step div > span {
  display: block;
}

.keeper-step div > strong {
  font-size: 14px;
}

.keeper-step div > span {
  margin-top: 3px;
  color: var(--text-soft);
  font-size: 12px;
}

.keeper-step div > span b {
  color: var(--text);
}

.maintenance-summary {
  background: #fcfdfc;
}

.maintenance-state {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 22px;
}

.state-orb {
  width: 15px;
  height: 15px;
  border: 4px solid #eceff1;
  border-radius: 50%;
  background: #899198;
  box-sizing: content-box;
}

.state-orb.running {
  border-color: #dff0e7;
  background: var(--primary);
}

.maintenance-state span,
.maintenance-state strong {
  display: block;
}

.maintenance-state div > span {
  color: var(--text-soft);
  font-size: 11px;
}

.maintenance-state strong {
  font-size: 18px;
}

.detail-list {
  display: grid;
  margin: 0;
}

.detail-list div {
  display: flex;
  min-height: 43px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-top: 1px solid var(--line);
}

.detail-list dt {
  color: var(--text-soft);
  font-size: 12px;
}

.detail-list dd {
  max-width: 65%;
  margin: 0;
  overflow-wrap: anywhere;
  text-align: right;
  font-size: 12px;
  font-weight: 600;
}

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

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

.capacity-strip {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 9px 12px;
  border: 1px solid #cfe1d8;
  border-radius: 6px;
  color: #4d5b54;
  background: #f3faf6;
  font-size: 12px;
}

.capacity-strip strong {
  color: var(--primary);
  font-size: 15px;
}

.maintenance-control .form-actions .button {
  min-width: 112px;
}

.stack-form .form-actions {
  margin-top: 4px;
}

dialog {
  width: min(calc(100vw - 28px), 500px);
  max-height: calc(100vh - 28px);
  padding: 0;
  overflow: auto;
  border: 0;
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(20, 25, 29, 0.54);
}

dialog:focus {
  outline: 0;
}

.dialog-card {
  display: grid;
  gap: 18px;
  padding: 22px;
}

.dialog-card.wide {
  min-width: 0;
}

dialog:has(.dialog-card.wide) {
  width: min(calc(100vw - 28px), 660px);
}

dialog:has(.dialog-card.extra-wide) {
  width: min(calc(100vw - 28px), 760px);
}

dialog:has(.compact-dialog) {
  width: min(calc(100vw - 28px), 430px);
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 18px;
}

.dialog-header p {
  margin: 5px 0 0;
  color: var(--text-soft);
  font-size: 12px;
}

.icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 5px;
  color: var(--text-soft);
  background: transparent;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.icon-button:hover {
  background: var(--surface-muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
}

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

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

.checkbox-field {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
  cursor: pointer;
}

.checkbox-field input {
  width: 17px;
  min-height: 17px;
  margin: 2px 0 0;
}

.checkbox-field strong,
.checkbox-field small {
  display: block;
}

.privacy-note,
.warning-note {
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 11px;
}

.privacy-note {
  color: #285d4a;
  background: var(--primary-soft);
}

.warning-note {
  color: var(--warning);
  background: var(--warning-soft);
}

.secret-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface-muted);
}

.secret-box code {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: all;
}

.generated-example {
  display: grid;
  gap: 7px;
  margin-top: 14px;
}

.generated-example > span {
  color: var(--text-soft);
  font-size: 12px;
}

.command-box code {
  overflow-wrap: anywhere;
  text-overflow: clip;
  white-space: normal;
}

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

.toast {
  display: flex;
  min-height: 45px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 13px;
  border: 1px solid #ccd2d6;
  border-left: 4px solid var(--primary);
  border-radius: 6px;
  background: #ffffff;
  box-shadow: var(--shadow);
  font-size: 12px;
  pointer-events: auto;
}

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

.toast button {
  padding: 0;
  border: 0;
  color: var(--text-soft);
  background: transparent;
  cursor: pointer;
}

.mobile-scrim {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

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

  .filter-bar .search-field {
    grid-column: 1 / -1;
  }

  .filter-bar > .button {
    align-self: end;
  }

}

@media (max-width: 820px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 180ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-scrim.visible {
    position: fixed;
    z-index: 25;
    inset: 0;
    display: block;
    background: rgba(20, 25, 29, 0.44);
  }

  .main {
    margin-left: 0;
  }

  .mobile-menu {
    display: block;
  }

  .topbar {
    justify-content: flex-start;
    padding: 11px 18px;
  }

  .topbar-actions {
    margin-left: auto;
  }

  .last-refresh {
    display: none;
  }

  .content {
    padding: 22px 18px 36px;
  }

  .panel-grid,
  .maintenance-layout {
    grid-template-columns: 1fr;
  }

  .keeper-flow {
    grid-template-columns: 1fr;
  }

}

@media (max-width: 580px) {
  .topbar {
    min-height: 68px;
    gap: 10px;
    padding: 9px 12px;
  }

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

  .topbar-actions .button {
    min-height: 36px;
    padding: 6px 10px;
  }

  .content {
    padding: 18px 12px 30px;
  }

  .section-heading {
    display: grid;
    margin-bottom: 15px;
  }

  .heading-actions {
    justify-content: stretch;
  }

  .heading-actions .button {
    flex: 1;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .stat-card {
    min-height: 102px;
    padding: 14px;
  }

  .stat-card strong {
    font-size: 24px;
  }

  .panel {
    padding: 15px;
  }

  .maintenance-fields {
    grid-template-columns: 1fr;
  }

  .capacity-strip {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .filter-bar,
  .filter-bar.compact {
    grid-template-columns: 1fr 1fr;
    padding: 10px;
  }

  .filter-bar .search-field,
  .filter-bar.compact label {
    grid-column: 1 / -1;
  }

  .filter-bar.compact .button {
    grid-column: 1 / -1;
  }

  .pagination {
    align-items: flex-start;
    flex-direction: column;
  }

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

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

  .dialog-card {
    padding: 17px;
  }

  .dialog-actions .button {
    flex: 1;
  }

  .secret-box {
    grid-template-columns: 1fr;
  }

  .secret-box code {
    overflow-wrap: anywhere;
    white-space: normal;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
