:root {
  --color-primary: #1f4e79;
  --color-primary-dark: #163a5a;
  --color-bg: #f3f6fa;
  --color-panel: #ffffff;
  --color-border: #d8dee8;
  --color-text: #1f2933;
  --color-muted: #6b7280;
  --color-success: #16a34a;
  --color-warning: #f59e0b;
  --color-danger: #dc2626;
  --color-info: #2563eb;
  --color-header-bg: #182433;
  --color-sidebar-bg: #202b3a;
  --color-sidebar-active: #1f4e79;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 13px;
}
button, input, select, textarea { font: inherit; }
button:focus,
.btn:focus,
.nav-item:focus {
  outline: none;
  box-shadow: none;
}
.hidden { display: none !important; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #eef3f8;
}
.login-card {
  width: min(380px, 100%);
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 12px 34px rgba(24, 36, 51, .16);
}
.login-title { font-size: 22px; font-weight: 700; color: var(--color-primary-dark); }
.login-subtitle { margin: 6px 0 18px; color: var(--color-muted); }
.login-hint { min-height: 20px; margin: 2px 0 12px; color: var(--color-danger); font-size: 12px; }
.login-submit { width: 100%; }
.topbar {
  height: 58px;
  background: var(--color-header-bg);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid #0f1722;
}
.brand-title { font-size: 18px; font-weight: 700; letter-spacing: .5px; }
.brand-subtitle { color: #9fb1c5; margin-top: 2px; font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.status-dot.online { background: var(--color-success); box-shadow: 0 0 0 3px rgba(22, 163, 74, .18); }
.role-badge { border: 1px solid #405268; border-radius: 14px; padding: 4px 10px; color: #d8e6f5; }

.layout { flex: 1; display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: 0; }
.sidebar { background: var(--color-sidebar-bg); padding: 14px 10px; border-right: 1px solid #182232; }
.nav-item {
  width: 100%; height: 38px; margin-bottom: 6px; padding: 0 12px;
  border: 0; border-radius: 4px; text-align: left; cursor: pointer;
  background: transparent; color: #cfdae7;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--color-sidebar-active); color: #fff; font-weight: 700; }

.content { min-width: 0; padding: 18px; overflow: auto; }
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 14px; }
h1 { margin: 0; font-size: 22px; }
p { margin: 6px 0 0; color: var(--color-muted); }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.card-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.card {
  background: var(--color-panel); border: 1px solid var(--color-border); border-radius: 6px;
  padding: 14px; box-shadow: 0 1px 2px rgba(18, 30, 48, .05);
}
.card-label { color: var(--color-muted); font-size: 12px; }
.card-value { margin-top: 8px; font-size: 24px; font-weight: 700; color: var(--color-primary-dark); }
.card-foot { margin-top: 6px; color: var(--color-muted); font-size: 12px; }

.panel { background: var(--color-panel); border: 1px solid var(--color-border); border-radius: 6px; margin-bottom: 14px; overflow: hidden; }
.panel-head { min-height: 44px; display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--color-border); background: #fafbfd; }
.panel-title { font-weight: 700; }
.panel-body { padding: 12px; }
.filter-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search-input, .form-control { height: 32px; padding: 5px 8px; border: 1px solid var(--color-border); border-radius: 4px; background: #fff; min-width: 160px; }
textarea.form-control { min-height: 84px; resize: vertical; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th, td { border-bottom: 1px solid var(--color-border); padding: 8px 10px; text-align: left; vertical-align: middle; white-space: nowrap; }
th { background: #eef3f8; color: #344156; font-weight: 700; }
tbody tr:hover { background: #f7fbff; }

.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 12px; font-size: 12px; font-weight: 700; }
.badge.active, .badge.approved, .badge.online { color: #0f7a36; background: #dcfce7; }
.badge.expiring_soon, .badge.pending { color: #9a5a00; background: #fef3c7; }
.badge.expired, .badge.rejected { color: #b91c1c; background: #fee2e2; }
.badge.revoked { color: #7f1d1d; background: #fecaca; }
.badge.offline { color: #4b5563; background: #e5e7eb; }
.badge.info { color: #1d4ed8; background: #dbeafe; }

.btn { height: 32px; border: 0; border-radius: 4px; padding: 0 12px; cursor: pointer; font-weight: 700; }
.btn-sm { height: 26px; padding: 0 8px; font-size: 12px; margin-right: 4px; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-success { background: var(--color-success); color: #fff; }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-secondary { background: #64748b; color: #fff; }
.btn-ghost { background: #e7edf5; color: var(--color-primary-dark); }
.btn-outline { background: #fff; color: var(--color-primary); border: 1px solid var(--color-primary); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(220px, 1fr)); gap: 12px; }
.form-field label { display: block; color: var(--color-muted); margin-bottom: 5px; }
.form-field.full { grid-column: 1 / -1; }
.form-actions { margin-top: 12px; display: flex; gap: 8px; justify-content: flex-end; }
.notice { border-left: 4px solid var(--color-info); background: #eff6ff; padding: 10px 12px; color: #1e3a8a; margin-bottom: 12px; }

.modal-root { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: center; justify-content: center; z-index: 20; }
.modal-root.hidden { display: none; }
.modal { width: min(560px, calc(100vw - 32px)); background: #fff; border-radius: 8px; box-shadow: 0 18px 50px rgba(0,0,0,.28); overflow: hidden; }
.modal-head { padding: 13px 16px; background: var(--color-header-bg); color: #fff; font-weight: 700; }
.modal-body { padding: 16px; }
.modal-actions { padding: 12px 16px; background: #f8fafc; border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: 8px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.kv-list { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; }
.kv-list dt { color: var(--color-muted); }
.kv-list dd { margin: 0; font-weight: 700; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: flex; overflow-x: auto; gap: 6px; padding: 8px; }
  .nav-item { width: auto; min-width: 108px; margin-bottom: 0; }
  .card-grid { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
  .two-col, .form-grid { grid-template-columns: 1fr; }
  .topbar { height: auto; align-items: flex-start; flex-direction: column; gap: 8px; padding: 12px; }
}
