:root {
  --sidebar-bg: #0f172a;
  --sidebar-bg-soft: #16213a;
  --accent: #2563eb;
  --accent-soft: #e8f0ff;
  --page-bg: #f4f6fa;
  --card-border: #e6ebf3;
  --ink: #0f172a;
  --muted: #64748b;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius-lg: 16px;
  --radius-md: 12px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 20px rgba(15, 23, 42, .04);
}

html, body {
  height: 100%;
}

body {
  background: var(--page-bg);
  color: var(--ink);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.svg-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: currentColor;
  stroke: currentColor;
}

/* ---------- shell ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 248px;
  flex: 0 0 248px;
  background: radial-gradient(1200px 500px at -10% -20%, #1d3a6b 0%, transparent 60%), var(--sidebar-bg);
  color: #cbd5e1;
  padding: 22px 16px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 10px 22px;
  color: #fff;
  text-decoration: none;
}

.brand:hover { color: #fff; }

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  font-weight: 800;
  font-size: 15px;
  letter-spacing: .5px;
  color: #fff;
  box-shadow: 0 8px 20px rgba(37, 99, 235, .35);
}

.brand-mark-lg {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  font-size: 19px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-text strong { font-size: 16px; letter-spacing: .2px; }
.brand-text small { font-size: 11px; color: #94a3b8; }

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

.side-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 9px;
  color: #a9b6cc;
  text-decoration: none;
  font-size: 14px;
  transition: background .16s ease, color .16s ease;
}

.side-link:hover {
  background: rgba(148, 163, 184, .1);
  color: #fff;
}

.side-link.active {
  background: rgba(59, 130, 246, .18);
  color: #fff;
  box-shadow: inset 3px 0 0 #60a5fa;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 10px 2px;
  border-top: 1px solid rgba(148, 163, 184, .12);
  font-size: 12px;
}

.sidebar-footer a { color: #94a3b8; text-decoration: none; }
.sidebar-footer a:hover { color: #fff; }

.version-pill {
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(148, 163, 184, .14);
  color: #cbd5e1;
  font-size: 11px;
}

/* ---------- main ---------- */
.app-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 68px;
  padding: 12px 28px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--card-border);
}

.topbar-title h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -.2px;
}

.crumbs {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

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

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px;
  color: var(--ink);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 6px 6px;
  border: 1px solid var(--card-border);
  background: #fff;
  border-radius: 999px;
  transition: box-shadow .15s ease;
}

.user-chip:hover { box-shadow: var(--shadow-sm); }

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
}

.user-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
}

.user-meta strong { font-size: 13px; }
.user-meta small { font-size: 11px; color: var(--muted); }

.app-content {
  padding: 24px 28px 40px;
  flex: 1 1 auto;
}

/* ---------- cards ---------- */
.panel {
  background: #fff;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--card-border);
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.panel-head .sub {
  color: var(--muted);
  font-size: 12px;
}

.panel-body { padding: 18px 20px; }

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

.stat-card {
  background: #fff;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.stat-card .label {
  color: var(--muted);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-card .value {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -.5px;
  margin-top: 8px;
  line-height: 1;
}

.stat-card .hint {
  color: var(--muted);
  font-size: 11px;
  margin-top: 8px;
}

.stat-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- tables ---------- */
.table-panel { overflow: hidden; }

.table {
  margin-bottom: 0;
  font-size: 13px;
}

.table > :not(caption) > * > * {
  padding: .7rem .85rem;
  vertical-align: middle;
}

.table thead th {
  background: #f8fafc;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: none;
  border-bottom: 1px solid var(--card-border);
  white-space: nowrap;
}

.table tbody tr:hover { background: #f9fbff; }

.code-text {
  font-family: "Cascadia Mono", "Consolas", ui-monospace, monospace;
  font-size: 12.5px;
  letter-spacing: .3px;
}

.hash-text {
  font-family: "Cascadia Mono", "Consolas", ui-monospace, monospace;
  font-size: 11px;
  color: var(--muted);
}

.badge-soft {
  font-weight: 600;
  font-size: 11.5px;
  padding: .32em .6em;
  border-radius: 6px;
}

.badge-unused { background: #eef2f7; color: #475569; }
.badge-active { background: #e8f7ee; color: #15803d; }
.badge-disabled { background: #fff4e5; color: #b45309; }
.badge-revoked { background: #fdeaea; color: #b91c1c; }
.badge-unbound { background: #f1f5f9; color: #64748b; }
.badge-success { background: #e8f7ee; color: #15803d; }
.badge-fail { background: #fdeaea; color: #b91c1c; }

.dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: 1px;
  background: currentColor;
}

/* ---------- toolbar & forms ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--card-border);
  background: #fff;
}

.toolbar .form-control,
.toolbar .form-select {
  font-size: 13px;
}

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

.search-box .form-control { padding-left: 34px; }

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

.form-label { font-size: 12.5px; font-weight: 600; color: #334155; }

.table-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--card-border);
  color: var(--muted);
  font-size: 12px;
}

.pagination { margin: 0; }
.page-link { font-size: 12.5px; padding: .3rem .6rem; }
.page-item.active .page-link { background: var(--accent); border-color: var(--accent); }

.empty-state {
  padding: 46px 20px;
  text-align: center;
  color: var(--muted);
}

.empty-state strong {
  display: block;
  color: #334155;
  margin-bottom: 4px;
}

/* ---------- dashboard ---------- */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 18px;
}

.trend-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 190px;
  padding: 8px 4px 0;
}

.trend-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.trend-bar-wrap {
  width: 100%;
  height: 150px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.trend-bar {
  width: 62%;
  min-height: 3px;
  background: linear-gradient(180deg, #60a5fa, #2563eb);
  border-radius: 5px 5px 2px 2px;
  transition: filter .15s ease;
}

.trend-col:hover .trend-bar { filter: brightness(1.08); }

.trend-label {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
}

.trend-value {
  font-size: 10.5px;
  font-weight: 700;
  color: #334155;
}

.failure-list { display: flex; flex-direction: column; gap: 12px; }

.failure-row { font-size: 12px; }

.failure-row .bar {
  height: 6px;
  border-radius: 999px;
  background: #eef2f7;
  margin-top: 6px;
  overflow: hidden;
}

.failure-row .bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #f87171, #dc2626);
  border-radius: 999px;
}

/* ---------- misc ---------- */
.section-title {
  font-size: 13px;
  font-weight: 700;
  color: #334155;
  margin: 0 0 10px;
}

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

.kv .k { color: var(--muted); font-size: 11.5px; margin-bottom: 2px; }
.kv .v { font-size: 13px; word-break: break-all; }

.mono {
  font-family: "Cascadia Mono", "Consolas", ui-monospace, monospace;
  font-size: 12px;
}

.copy-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 2px;
  line-height: 1;
}

.copy-btn:hover { color: var(--accent); }

.offcanvas, .modal-content { border-radius: 14px; }

.nav-tabs .nav-link { font-size: 13.5px; color: var(--muted); }
.nav-tabs .nav-link.active { color: var(--ink); font-weight: 600; }

.timeline { position: relative; padding-left: 18px; }
.timeline::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: #e6ebf3;
}
.timeline-item { position: relative; padding: 0 0 16px 8px; }
.timeline-item::before {
  content: "";
  position: absolute;
  left: -17px;
  top: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
}

.json-view {
  background: #0f172a;
  color: #cbd5e1;
  border-radius: 8px;
  padding: 12px;
  font-family: "Cascadia Mono", "Consolas", ui-monospace, monospace;
  font-size: 11.5px;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover, .btn-primary:focus { background: #1d4ed8; border-color: #1d4ed8; }

.page-loading {
  padding: 50px;
  text-align: center;
  color: var(--muted);
}

/* ---------- login ---------- */
.login-body {
  min-height: 100vh;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(37, 99, 235, .35), transparent 60%),
    radial-gradient(700px 500px at 100% 100%, rgba(99, 102, 241, .22), transparent 55%),
    #0b1222;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-wrap { width: 100%; max-width: 430px; }

.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 30px 30px 24px;
  box-shadow: 0 30px 80px rgba(2, 6, 23, .45);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.login-brand h1 {
  font-size: 19px;
  font-weight: 800;
  margin: 0;
  letter-spacing: -.3px;
}

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

.login-hint {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 11.5px;
  text-align: center;
}

.login-footer {
  text-align: center;
  color: rgba(203, 213, 225, .55);
  font-size: 11.5px;
  margin-top: 18px;
}

/* ---------- responsive ---------- */
@media (max-width: 1199.98px) {
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 991.98px) {
  .topbar { padding: 10px 16px; }
  .app-content { padding: 18px 16px 32px; }
  .sidebar-offcanvas {
    background: var(--sidebar-bg);
    color: #cbd5e1;
    width: 268px;
  }
  .sidebar-offcanvas .offcanvas-header { border-bottom: 1px solid rgba(148, 163, 184, .12); }
  .sidebar-offcanvas .side-nav { padding: 4px 6px; }
  .sidebar-offcanvas .brand { padding: 4px 0 0; }
  .sidebar-offcanvas .brand-text small { color: #94a3b8; }
}

@media (max-width: 767.98px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar-title h1 { font-size: 16px; }
  .crumbs { display: none; }
  .user-meta { display: none; }
  .kv-grid { grid-template-columns: 1fr; }
  .trend-chart { gap: 4px; height: 160px; }
  .trend-bar-wrap { height: 120px; }
  .trend-label { font-size: 9px; }
  .toolbar { padding: 12px; }
  .search-box { max-width: none; flex-basis: 100%; }
  .login-card { padding: 24px 20px 20px; }
}
