:root {
  --brand: #3b6ef6;
  --brand-dark: #2c56cc;
  --brand-soft: #eef3ff;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #1b2233;
  --muted: #7a8499;
  --border: #e6e9f2;
  --danger: #e5484d;
  --danger-soft: #fdeeee;
  --warn: #b7791f;
  --warn-soft: #fdf5e6;
  --success: #1f9d63;
  --success-soft: #e8f7ef;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(24, 39, 75, 0.06);
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

body { -webkit-font-smoothing: antialiased; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- 登录页 ---------- */
.login-view {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 16px;
  background:
    radial-gradient(900px 500px at 12% 8%, rgba(59, 110, 246, 0.14), transparent 60%),
    radial-gradient(700px 420px at 88% 92%, rgba(31, 157, 99, 0.10), transparent 60%),
    var(--bg);
}

.login-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(24, 39, 75, 0.10);
  padding: 34px 32px 26px;
}

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

.login-brand h1 { font-size: 22px; margin: 0; letter-spacing: 0.2px; }
.login-brand p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.logo-mark {
  width: 52px;
  height: 52px;
  border-radius: 15px;
  background: linear-gradient(135deg, #5a86ff, #2c56cc);
  color: #fff;
  font-weight: 700;
  font-size: 24px;
  display: grid;
  place-items: center;
  box-shadow: 0 10px 22px rgba(59, 110, 246, 0.32);
}
.logo-mark.small { width: 40px; height: 40px; border-radius: 12px; font-size: 19px; box-shadow: none; }

.login-form { display: grid; gap: 12px; }
.login-form label { font-weight: 600; font-size: 13px; }
.login-form input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fbfcff;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.login-form input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(59, 110, 246, 0.14);
}
.form-error { color: var(--danger); font-size: 13px; margin: 2px 0 0; }
.login-foot { margin: 22px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }

/* ---------- 布局 ---------- */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 16px 18px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 0 6px 26px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 16px; }
.brand-text span { font-size: 12px; color: var(--muted); }

.nav { display: grid; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #495266;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.nav-item svg { width: 19px; height: 19px; fill: currentColor; opacity: 0.85; }
.nav-item:hover { background: #f5f7fc; color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }

.sidebar-foot {
  margin-top: auto;
  padding: 14px 8px 0;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
}
.sidebar-foot .version { margin-left: auto; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }

.main { min-width: 0; padding: 24px 30px 40px; }

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.topbar h2 { margin: 0; font-size: 21px; letter-spacing: 0.2px; }
.topbar p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; gap: 8px; }

/* ---------- 通用控件 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.06s, background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
  font-family: inherit;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; fill: currentColor; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 6px 16px rgba(59, 110, 246, 0.24); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled, .btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-ghost { background: var(--surface); border-color: var(--border); color: #46506a; }
.btn-ghost:hover { border-color: #c9d2e6; background: #fafbff; }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: #fbdcdc; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; padding: 12px; }
.btn-link {
  border: 0;
  background: none;
  color: var(--brand);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 2px;
  font-family: inherit;
}
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: var(--danger); }

.input {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 9px 12px;
  font-size: 13.5px;
  color: var(--text);
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(59, 110, 246, 0.12); }
.search { min-width: 220px; }

/* ---------- 概览 ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow);
}
.stat-card .stat-label { color: var(--muted); font-size: 13px; }
.stat-card strong { font-size: 30px; letter-spacing: -0.5px; font-weight: 700; }
.stat-card .stat-hint { color: var(--muted); font-size: 12px; }
.stat-card.accent { border-color: #d8e2ff; background: linear-gradient(180deg, #f7faff, #ffffff); }
.stat-card.accent strong { color: var(--brand-dark); }
.stat-card.warn strong { color: var(--warn); }

.overview-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.panel h3 { margin: 0 0 14px; font-size: 15px; }
.today-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.today-row strong { display: block; font-size: 28px; margin-top: 4px; }
.copy-row { display: flex; gap: 8px; align-items: center; margin: 10px 0; }
.copy-row code {
  flex: 1;
  background: #f6f8fd;
  border: 1px dashed #d5ddef;
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 12.5px;
  color: #34405a;
  overflow: auto;
  white-space: nowrap;
}

/* ---------- 表格 ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.toolbar > .muted { margin: 0; flex: 1; }
.toolbar .btn-primary { margin-left: auto; }

.table-panel { padding: 0; overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: #fafbfe;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 13px 16px;
  border-bottom: 1px solid #f0f2f8;
  vertical-align: middle;
  font-size: 13px;
}
.data-table tbody tr:hover { background: #fbfcff; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.actions-col { width: 210px; }
.row-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.code-text {
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: #24304a;
  background: #f5f7fd;
  border-radius: 6px;
  padding: 4px 7px;
  white-space: nowrap;
}
.device-cell { display: flex; flex-direction: column; gap: 2px; max-width: 210px; }
.device-cell .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-cell .meta { color: var(--muted); font-size: 11.5px; }
.cell-muted { color: var(--muted); }
.note-cell { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.active { color: var(--success); background: var(--success-soft); }
.badge.disabled { color: var(--danger); background: var(--danger-soft); }
.badge.expired { color: var(--warn); background: var(--warn-soft); }
.badge.bound { color: var(--brand-dark); background: var(--brand-soft); }
.badge.unbound { color: #7a8499; background: #f1f3f8; }
.badge.plain { background: #f1f3f8; color: #5b6579; }

.table-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: #fcfdff;
  font-size: 12.5px;
}
.pager { display: flex; gap: 8px; }

.empty { padding: 46px 20px; text-align: center; color: var(--muted); }
.empty p { margin: 0 0 12px; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(18, 26, 44, 0.42);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
  backdrop-filter: blur(2px);
}
.modal-card {
  width: min(520px, 100%);
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 30px 70px rgba(15, 25, 48, 0.28);
  animation: pop 0.16s ease-out;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
}
@keyframes pop { from { transform: translateY(8px) scale(0.98); opacity: 0; } }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 16px; }
.icon-btn {
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}
.icon-btn:hover { background: #f2f4fa; color: var(--text); }
.modal-body { padding: 20px; display: grid; gap: 14px; overflow: auto; }
.modal-body label { display: grid; gap: 7px; font-size: 13px; font-weight: 600; color: #3c4559; }
.modal-body .input { width: 100%; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.code-block {
  margin: 0;
  padding: 14px;
  border-radius: 10px;
  background: #f6f8fd;
  border: 1px dashed #d5ddef;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.85;
  max-height: 300px;
  overflow: auto;
  white-space: pre-wrap;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 12px 30px rgba(15, 25, 48, 0.3);
  z-index: 90;
  animation: pop 0.16s ease-out;
}
.toast.error { background: #b3363a; }

/* ---------- 响应式 ---------- */
@media (max-width: 1080px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overview-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    padding: 14px 16px;
    flex-direction: row;
    align-items: center;
    gap: 14px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .brand { padding: 0; }
  .nav { display: flex; margin-left: auto; }
  .nav-item { padding: 9px 11px; font-size: 13px; }
  .nav-item svg { display: none; }
  .sidebar-foot { display: none; }
  .main { padding: 18px 16px 32px; }
  .topbar { margin-bottom: 16px; }
  .topbar-actions .btn { padding: 8px 11px; }
  .table-panel { overflow-x: auto; }
  .data-table { min-width: 820px; }
  .search { flex: 1; min-width: 150px; }
  .toolbar .btn-primary { margin-left: 0; }
  .field-row { grid-template-columns: 1fr; }
}
