:root {
  --bg: #0f1218;
  --panel: #161b24;
  --panel-2: #1c2230;
  --border: #262e3d;
  --text: #e6ecf5;
  --muted: #8a94a6;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --warn: #f59e0b;
  --ok: #22c55e;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; }

.hidden { display: none !important; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p.sub { color: var(--muted); margin: 0 0 22px; font-size: 13px; }

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 208px;
  flex: 0 0 208px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
}

.brand { font-weight: 600; font-size: 15px; padding: 6px 10px 18px; letter-spacing: 0.3px; }
.brand span { color: var(--primary); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: 4px;
  user-select: none;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: rgba(59, 130, 246, 0.15); color: var(--primary); font-weight: 500; }

.sidebar-footer { margin-top: auto; padding: 10px; color: var(--muted); font-size: 12px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 58px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h2 { font-size: 16px; margin: 0; font-weight: 500; }
.topbar .who { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 12px; }

.content { padding: 24px; min-width: 1180px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.card h3 { margin: 0 0 14px; font-size: 15px; font-weight: 500; }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.stat .label { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.stat .value { font-size: 26px; font-weight: 600; }
.stat.accent .value { color: var(--primary); }
.stat.warn .value { color: var(--warn); }
.stat.danger .value { color: var(--danger); }
.stat.ok .value { color: var(--ok); }

.btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
}
.btn:hover { background: var(--primary-hover); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn.ghost:hover { background: var(--panel-2); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #dc2626; }
.btn.sm { padding: 5px 9px; font-size: 12px; border-radius: 6px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
input, select, textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { min-height: 110px; resize: vertical; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type="text"] { width: 240px; }
.toolbar select { width: auto; min-width: 120px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
tbody tr:hover { background: var(--panel-2); }
td.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.4px; }
td.actions { white-space: nowrap; }
td.actions .btn { margin-right: 4px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1.6;
}
.badge.ok { background: rgba(34, 197, 94, 0.15); color: var(--ok); }
.badge.gray { background: rgba(138, 148, 166, 0.15); color: var(--muted); }
.badge.warn { background: rgba(245, 158, 11, 0.15); color: var(--warn); }
.badge.danger { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.badge.blue { background: rgba(59, 130, 246, 0.15); color: var(--primary); }

.expired { color: var(--danger); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--muted); }
.truncate { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: bottom; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 14px; color: var(--muted); font-size: 13px; }

.empty { text-align: center; color: var(--muted); padding: 36px 0; }
.loading { text-align: center; color: var(--muted); padding: 36px 0; }

.toast-root { position: fixed; top: 18px; right: 18px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  padding: 10px 16px;
  min-width: 200px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: slidein 0.2s ease;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--ok); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-root {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 20px;
  z-index: 9000;
  overflow: auto;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 560px;
  max-width: 100%;
  padding: 20px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}
.modal.wide { width: 760px; }
.modal h3 { margin: 0 0 16px; font-size: 16px; font-weight: 500; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.chart { width: 100%; height: 220px; }
.legend { display: flex; gap: 18px; color: var(--muted); font-size: 12px; margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }

.timeline { border-left: 2px solid var(--border); margin-left: 8px; padding-left: 16px; }
.timeline .item { position: relative; padding-bottom: 14px; }
.timeline .item::before {
  content: "";
  position: absolute;
  left: -23px;
  top: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
}
.timeline .time { color: var(--muted); font-size: 12px; }

.detail-grid { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; font-size: 13px; }
.detail-grid .k { color: var(--muted); }

.codebox {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  max-height: 260px;
  overflow: auto;
  white-space: pre;
  line-height: 1.7;
}

.form-inline { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 16px; }
.checkbox { display: flex; align-items: center; gap: 8px; color: var(--text); }
.checkbox input { width: auto; }

.initial-hint {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 18px;
  font-size: 13px;
}
.initial-hint.simple { color: var(--muted); line-height: 1.7; }
.initial-hint .initial-title { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.initial-hint .initial-row { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.initial-hint .initial-row span { color: var(--muted); }
.initial-hint code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(59, 130, 246, 0.12);
  color: var(--text);
  padding: 2px 8px;
  border-radius: 5px;
}
.initial-hint .initial-note { color: var(--muted); font-size: 12px; margin: 8px 0; line-height: 1.6; }

.tip {
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.7;
  margin-bottom: 16px;
  background: rgba(59, 130, 246, 0.1);
  color: var(--text);
}
.tip.warn { background: rgba(245, 158, 11, 0.12); color: #f6c66b; }
