:root {
  --bg: #f3f6fb;
  --bg-soft: #eef4fb;
  --card: #ffffff;
  --line: #dbe3ee;
  --line-strong: #c9d5e4;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-soft: #e8f0ff;
  --success: #0f766e;
  --success-soft: #e6fffb;
  --warning: #b45309;
  --warning-soft: #fff4e5;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --shadow: 0 20px 40px rgba(15, 23, 42, 0.08);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: Inter, "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(37, 99, 235, 0.08), transparent 180px),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.login-card {
  width: min(480px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 32px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--primary), #4f8cff);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0;
}

.login-card h1,
.brand h1,
.topbar h2,
.section-head h2 {
  margin: 0;
  letter-spacing: 0;
}

.login-card h1 {
  font-size: 28px;
  margin-top: 18px;
}

.login-card p,
.brand p,
.topbar p,
.section-head p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.login-form,
.tool-form {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

.login-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

.login-form input,
.tool-form input,
.tool-form select {
  width: 100%;
  min-width: 0;
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: #fff;
  padding: 0 12px;
  color: var(--text);
}

.login-form input:focus,
.tool-form input:focus,
.tool-form select:focus {
  outline: 2px solid rgba(37, 99, 235, 0.16);
  border-color: var(--primary);
}

.login-form button,
.tool-form button,
.logout,
.nav-item,
.ghost-action {
  border: 0;
  border-radius: 10px;
  transition: all 0.18s ease;
}

.login-form button,
.tool-form button {
  height: 42px;
  background: linear-gradient(135deg, var(--primary), #4f8cff);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 10px 18px rgba(37, 99, 235, 0.18);
}

.login-form button:hover,
.tool-form button:hover,
.logout:hover,
.nav-item:hover,
.ghost-action:hover {
  transform: translateY(-1px);
}

.error,
.alert {
  margin-top: 16px;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
}

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

.alert {
  color: #1d4ed8;
  background: var(--primary-soft);
  border: 1px solid rgba(37, 99, 235, 0.12);
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 20px;
  padding: 20px;
}

.sidebar,
.content {
  min-width: 0;
}

.sidebar {
  position: sticky;
  top: 20px;
  align-self: start;
  display: grid;
  gap: 16px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px;
}

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

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

.brand p {
  font-size: 13px;
}

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

.nav-item {
  text-align: left;
  padding: 11px 14px;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
}

.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: rgba(37, 99, 235, 0.16);
  font-weight: 600;
}

.logout {
  height: 42px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  font-weight: 600;
}

.content {
  display: grid;
  gap: 16px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 22px 24px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

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

.page-section {
  display: grid;
  gap: 18px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 24px;
}

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

.section-head p {
  font-size: 14px;
}

.metric-grid,
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}

.metric-card,
.info-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  background: linear-gradient(180deg, #fff, #fafcff);
}

.metric-card {
  position: relative;
}

.metric-card::after {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  height: 4px;
  border-radius: 16px 16px 0 0;
  background: linear-gradient(90deg, var(--primary), #63a4ff);
}

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

.metric-card strong,
.info-card strong {
  display: block;
  margin-top: 10px;
  font-size: 28px;
  line-height: 1;
  letter-spacing: 0;
}

.info-card strong {
  font-size: 18px;
}

.tool-form {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  align-items: center;
}

.tool-form button {
  min-width: 120px;
}

table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
}

thead th {
  background: #f8fbff;
  color: var(--muted);
  font-weight: 600;
}

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

tbody tr:hover {
  background: #f9fbff;
}

tbody tr.is-selected {
  background: #eef4ff;
}

tbody tr.is-selected:hover {
  background: #e6f0ff;
}

.empty-cell {
  padding: 18px 12px;
  text-align: center;
  color: var(--muted);
  background: #fafcff;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-active,
.badge-success,
.badge-online {
  background: var(--success-soft);
  color: var(--success);
}

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

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

.badge-disabled,
.badge-error,
.badge-revoked,
.badge-expired {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-expiring_soon,
.badge-below_minimum,
.badge-warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.badge-bound,
.badge-online {
  background: var(--success-soft);
  color: var(--success);
}

.badge-unbound,
.badge-offline {
  background: #edf2f7;
  color: #64748b;
}

.badge-muted,
.badge-unknown {
  background: #edf2f7;
  color: #64748b;
}

.timeline {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 12px;
}

.timeline li {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

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

.timeline span {
  color: var(--primary);
  font-weight: 600;
}

.timeline em {
  color: var(--muted);
  margin-left: auto;
  font-style: normal;
}

.ghost-action {
  min-height: 34px;
  padding: 0 12px;
  background: #eef4ff;
  color: var(--primary);
  border: 1px solid rgba(37, 99, 235, 0.12);
}

.ghost-action.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(185, 28, 28, 0.14);
}

.ghost-action:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.toast {
  position: fixed;
  z-index: 1000;
  top: 24px;
  right: 24px;
  width: min(360px, calc(100vw - 32px));
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 14px 16px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--line);
  border-left: 4px solid var(--success);
  border-radius: 10px;
  box-shadow: 0 16px 34px rgba(15, 23, 42, 0.16);
  animation: toast-in 0.2s ease-out;
}

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

.toast-icon {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  color: var(--success);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

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

.toast-message {
  min-width: 0;
  flex: 1;
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.toast-close {
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 6px;
  color: #9aa4b2;
  background: transparent;
  font-size: 20px;
  font-weight: 300;
  line-height: 1;
}

.toast-close:hover {
  color: var(--text);
  background: #f1f5f9;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

.list-summary,
.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.pager {
  justify-content: flex-end;
}

.admin-search-form {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  align-items: end;
}

.date-field {
  display: grid;
  grid-template-rows: 16px 42px;
  align-content: end;
  gap: 6px;
  min-width: 0;
}

.date-field span {
  color: var(--muted);
  font-size: 13px;
  line-height: 16px;
}

.date-field input {
  box-sizing: border-box;
}

.split-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.panel-form {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  padding: 18px;
}

.panel-head h3,
.panel-head p {
  margin: 0;
}

.panel-head h3 {
  font-size: 18px;
}

.panel-head p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.check-tile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafdff;
}

.check-tile input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.form-grid {
  display: grid;
  gap: 12px;
}

.form-grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.form-grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.field {
  display: grid;
  gap: 6px;
}

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

.field input,
.field select,
.field textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  height: 42px;
}

.field textarea {
  height: auto;
  min-height: 104px;
  resize: vertical;
  padding: 12px;
}

.field-wide {
  grid-column: 1 / -1;
}

.admin-form {
  align-items: start;
}

.field input[readonly] {
  background: #f8fbff;
  cursor: not-allowed;
}

.form-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.form-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

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

.table-actions .ghost-action {
  min-width: 72px;
}

.table-shell th.select-cell,
.table-shell td.select-cell {
  width: 44px;
  min-width: 44px;
  text-align: center;
}

.table-shell td.select-cell input[type="checkbox"],
.table-shell th.select-cell input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary);
}

.stack-cell {
  display: grid;
  gap: 4px;
}

.stack-cell strong {
  font-size: 14px;
  line-height: 1.35;
}

.stack-cell span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  word-break: break-all;
}

.kv-summary {
  display: grid;
  gap: 12px;
}

.kv-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.kv-row span {
  color: var(--muted);
}

.kv-row strong {
  font-size: 16px;
}

.device-detail-card .kv-row strong {
  word-break: break-all;
  text-align: right;
}

.license-detail-card .kv-row strong {
  word-break: break-all;
  text-align: right;
}

.badge-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.panel-preview {
  min-height: 100%;
}

.panel-preview pre {
  margin: 0;
  min-height: 100%;
}

.detail-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
}

.detail-modal-backdrop {
  position: fixed;
  inset: 0;
  border: 0;
  padding: 0;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(2px);
  cursor: pointer;
}

.detail-modal-dialog {
  position: relative;
  z-index: 1;
  width: min(840px, 100%);
  min-height: 0;
  max-height: calc(100vh - 48px);
  overflow: auto;
}

.detail-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.detail-modal-close {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  line-height: 1;
  font-size: 20px;
}

.detail-modal-close:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

pre {
  overflow: auto;
  background: #0f172a;
  color: #dbeafe;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.table-shell {
  overflow: auto;
}

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

  .sidebar {
    position: relative;
    top: auto;
  }
}

@media (max-width: 720px) {
  .shell,
  .login-shell {
    padding: 14px;
  }

  .page-section,
  .topbar,
  .sidebar,
  .login-card {
    border-radius: 16px;
  }

  .topbar,
  .section-head {
    align-items: start;
    flex-direction: column;
  }

  table,
  .tool-form,
  .metric-grid,
  .info-grid {
    min-width: 0;
  }

  .timeline em {
    margin-left: 0;
  }

  .detail-modal {
    padding: 14px;
  }

  .detail-modal-dialog {
    max-height: calc(100vh - 28px);
  }
}
