/* ============================================================
   LicenseSoft 通用样式
   设计变量统一在 :root，页面只做组合，不写魔法色值
   ============================================================ */
:root {
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-soft: #eff6ff;
  --purple: #8b5cf6;
  --green: #10b981;
  --orange: #f59e0b;
  --red: #ef4444;

  --text: #1f2937;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --border: #e5e7eb;
  --border-2: #f0f0f4;
  --bg: #f5f7fa;
  --surface: #ffffff;

  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .04);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .12);

  --sidebar-w: 220px;
  --topbar-h: 56px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------- 登录页 ---------------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 15% 10%, #1d4ed8 0%, transparent 60%),
    radial-gradient(900px 500px at 90% 90%, #0ea5e9 0%, transparent 55%),
    linear-gradient(135deg, #0f172a 0%, #111827 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 36px 32px 28px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.login-brand .mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.login-title { font-size: 19px; font-weight: 700; letter-spacing: .3px; }
.login-sub { color: var(--text-2); font-size: 13px; margin-bottom: 24px; }

.login-form .field { margin-bottom: 16px; }
.login-form label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }

.login-btn {
  width: 100%;
  margin-top: 8px;
  height: 42px;
  font-size: 15px;
}

.login-tip {
  margin-top: 18px;
  font-size: 12px;
  color: var(--text-3);
  text-align: center;
  line-height: 1.8;
}

/* ---------------- 布局 ---------------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
}

.sidebar-brand {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-2);
  font-weight: 700;
  font-size: 15px;
}

.sidebar-brand .mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  color: #fff; display: flex; align-items: center; justify-content: center;
}

.sidebar-nav { padding: 10px 8px; flex: 1; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  cursor: pointer;
  font-size: 14px;
  user-select: none;
  margin-bottom: 2px;
}

.nav-item:hover { background: #f3f4f6; color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--primary-soft); color: var(--primary-hover); font-weight: 600; }
.nav-item .ico { width: 18px; text-align: center; opacity: .85; }

.sidebar-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border-2);
  font-size: 12px;
  color: var(--text-3);
}

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 { font-size: 16px; margin: 0; font-weight: 600; }

.user-box { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-2); }
.user-box .avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary-hover);
  display: flex; align-items: center; justify-content: center; font-weight: 600;
}

.content { padding: 20px; flex: 1; }

/* ---------------- 组件 ---------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.panel-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-2);
  flex-wrap: wrap;
}

.panel-hd h2 { font-size: 15px; margin: 0; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.panel-hd h2::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--primary);
}
.panel-bd { padding: 16px; }
.panel-bd.flush { padding: 0; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.stat::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--primary);
}
.stat.c-green::before { background: var(--green); }
.stat.c-orange::before { background: var(--orange); }
.stat.c-red::before { background: var(--red); }
.stat.c-purple::before { background: var(--purple); }

.stat .label { font-size: 12px; color: var(--text-2); }
.stat .value { font-size: 24px; font-weight: 700; line-height: 1.3; margin-top: 2px; }
.stat .sub { font-size: 12px; color: var(--text-3); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}

.btn:hover { border-color: #d1d5db; background: #f9fafb; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { color: var(--red); border-color: #fecaca; background: #fef2f2; }
.btn.danger:hover { background: #fee2e2; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.text { border-color: transparent; background: transparent; color: var(--primary); }
.btn.text:hover { background: var(--primary-soft); }

.input, .select, .textarea {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

.textarea { height: auto; padding: 8px 10px; resize: vertical; line-height: 1.6; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59, 130, 246, .12); }
.input[readonly] { background: #f9fafb; color: var(--text-2); }
.select { padding-right: 26px; }

.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.toolbar .input, .toolbar .select { width: auto; min-width: 150px; }
.toolbar .spacer { flex: 1; }

.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-2);
  text-align: left;
  vertical-align: middle;
}
table.grid th { background: #fafbfc; color: var(--text-2); font-weight: 600; white-space: nowrap; }
table.grid tbody tr:hover { background: #fafbff; }
table.grid td.nowrap { white-space: nowrap; }
table.grid .mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 12px; }
table.grid .muted { color: var(--text-3); }
table.grid .actions { display: flex; gap: 6px; flex-wrap: wrap; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 20px;
  font-size: 12px;
  line-height: 20px;
  white-space: nowrap;
}
.badge.ok { background: #ecfdf5; color: #047857; }
.badge.warn { background: #fffbeb; color: #b45309; }
.badge.danger { background: #fef2f2; color: #b91c1c; }
.badge.info { background: #eff6ff; color: #1d4ed8; }
.badge.muted { background: #f3f4f6; color: var(--text-2); }

.empty { padding: 40px 16px; text-align: center; color: var(--text-3); font-size: 13px; }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 12px 16px; color: var(--text-2); font-size: 13px; }

.alert {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
  border: 1px solid transparent;
}
.alert.error { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.alert.success { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.alert.info { background: var(--primary-soft); color: #1d4ed8; border-color: #bfdbfe; }
.alert.warn { background: #fffbeb; color: #b45309; border-color: #fde68a; }
[hidden] { display: none !important; }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 60px 16px; overflow-y: auto; z-index: 100;
}
.modal {
  width: 100%; max-width: 640px; background: var(--surface);
  border-radius: 10px; box-shadow: var(--shadow-lg); overflow: hidden;
}
.modal.wide { max-width: 820px; }
.modal-hd { padding: 14px 18px; border-bottom: 1px solid var(--border-2); font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.modal-bd { padding: 18px; max-height: 62vh; overflow-y: auto; }
.modal-ft { padding: 12px 18px; border-top: 1px solid var(--border-2); display: flex; justify-content: flex-end; gap: 8px; background: #fafbfc; }
.modal-close { cursor: pointer; color: var(--text-3); font-size: 18px; line-height: 1; background: none; border: none; }

/* Toast */
.toast-wrap { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  padding: 9px 16px; border-radius: 20px; font-size: 13px; color: #fff;
  background: rgba(17, 24, 39, .92); box-shadow: var(--shadow-lg);
  animation: toast-in .18s ease-out;
}
.toast.success { background: #10b981; }
.toast.error { background: #ef4444; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* 对接说明 */
.doc h3 { font-size: 14px; margin: 20px 0 8px; padding-left: 8px; border-left: 3px solid var(--primary); }
.doc h3:first-child { margin-top: 0; }
.doc p, .doc li { color: var(--text-2); font-size: 13px; }
.doc ul, .doc ol { padding-left: 20px; margin: 6px 0; }
.doc code { background: #f3f4f6; padding: 1px 5px; border-radius: 4px; font-size: 12px; font-family: ui-monospace, Consolas, monospace; color: #b91c1c; }
.doc pre {
  background: #0f172a; color: #e2e8f0; padding: 14px 16px; border-radius: var(--radius-sm);
  overflow-x: auto; font-size: 12px; line-height: 1.7; margin: 8px 0;
  font-family: ui-monospace, Consolas, monospace;
}
.doc table.grid td code { white-space: nowrap; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; font-size: 13px; }
.kv .k { color: var(--text-2); }

.secret-box {
  background: #fffbeb; border: 1px dashed #f59e0b; border-radius: var(--radius-sm);
  padding: 12px; font-family: ui-monospace, Consolas, monospace; font-size: 13px;
  word-break: break-all; margin: 8px 0;
}

.mini-chart { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 8px; }
.mini-chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.mini-chart .bar { width: 100%; max-width: 34px; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; }
.mini-chart .bar.deny { background: #fca5a5; }
.mini-chart .cap { font-size: 11px; color: var(--text-3); }

.copy-inline { cursor: pointer; color: var(--primary); font-size: 12px; margin-left: 6px; }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  .sidebar { position: static; width: 100%; flex: none; }
  .layout { flex-direction: column; }
  .main { margin-left: 0; }
  .field-row { grid-template-columns: 1fr; }
}
