:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --bg: #f3f4f6;
  --card: #ffffff;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

a { color: var(--primary); text-decoration: none; }

/* ---------- login ---------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 55%, #38bdf8 100%);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .35);
  padding: 40px 34px 32px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
  text-align: center;
}

.login-card .sub {
  margin: 0 0 28px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.field { margin-bottom: 16px; }

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--muted);
}

input[type="text"], input[type="password"], input[type="number"], input[type="date"],
input[type="search"], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

input[disabled], select[disabled] {
  background: #f9fafb;
  color: var(--muted);
}

textarea { resize: vertical; min-height: 64px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
  line-height: 1.4;
}

.btn:hover { border-color: #cbd5e1; background: #f9fafb; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-danger { color: var(--danger); }
.btn-danger:hover { background: #fef2f2; border-color: #fca5a5; }

.btn-sm { padding: 4px 9px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ---------- layout ---------- */
.topbar {
  height: 58px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; }

.brand .logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 15px; font-weight: 700;
}

.topbar .user { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 13px; }

.container { max-width: 1280px; margin: 0 auto; padding: 22px 24px 60px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.toolbar .spacer { flex: 1; }

.toolbar select, .toolbar input[type="search"] { width: auto; min-width: 150px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

table { width: 100%; border-collapse: collapse; }

th, td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th { background: #f9fafb; font-weight: 600; font-size: 13px; color: var(--muted); white-space: nowrap; }

tbody tr:hover { background: #fafafa; }
tbody tr:last-child td { border-bottom: none; }

.name-cell { font-weight: 500; }
.name-cell .id { color: #9ca3af; font-weight: 400; font-size: 12px; margin-left: 4px; }

.short-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  color: var(--primary);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 18px;
  background: #f3f4f6;
  color: var(--muted);
}

.badge-on { background: #dcfce7; color: #15803d; }
.badge-off { background: #fee2e2; color: #b91c1c; }
.badge-warn { background: #fef3c7; color: #b45309; }

.actions { display: flex; gap: 6px; flex-wrap: wrap; }

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

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}

.pager .pages { display: flex; gap: 6px; align-items: center; }

/* ---------- modals ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 50;
}

.modal-mask.open { display: flex; }

.modal {
  width: 100%;
  max-width: 620px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .3);
  animation: pop .16s ease-out;
}

.modal-lg { max-width: 900px; }

@keyframes pop {
  from { transform: translateY(-8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 { margin: 0; font-size: 16px; }

.modal-close {
  border: none;
  background: none;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}

.modal-close:hover { background: #f3f4f6; color: var(--text); }

.modal-body { padding: 20px; }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: #fafafa;
  border-radius: 0 0 12px 12px;
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

@media (max-width: 640px) {
  .grid2 { grid-template-columns: 1fr; }
  .container { padding: 14px; }
  .topbar { padding: 0 14px; }
  .hide-sm { display: none; }
}

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }

.tab {
  padding: 9px 16px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-family: inherit;
}

.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- channels ---------- */
.channel-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 12px;
  background: #fcfcfd;
}

.channel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.channel-head .title { font-weight: 600; font-size: 13px; }

.channel-head .spacer { flex: 1; }

.channel-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.channel-grid .full { grid-column: 1 / -1; }

.channel-grid label { font-size: 12px; color: var(--muted); display: block; }

.channel-grid input, .channel-grid select { margin-top: 4px; padding: 7px 9px; font-size: 13px; }

@media (max-width: 760px) {
  .channel-grid { grid-template-columns: 1fr 1fr; }
}

.hint { font-size: 12px; color: var(--muted); margin: 4px 0 12px; line-height: 1.6; }

.checkline { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.checkline input { width: auto; }

/* ---------- stats ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }

.stat-card { background: #f9fafb; border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.stat-card .k { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat-card .v { font-size: 24px; font-weight: 600; }

.chart { display: flex; align-items: flex-end; gap: 8px; height: 140px; padding: 8px 0 0; }
.chart .bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.chart .bar { width: 100%; max-width: 46px; background: linear-gradient(180deg, #60a5fa, #2563eb); border-radius: 6px 6px 0 0; min-height: 2px; transition: height .2s; }
.chart .bar-label { font-size: 11px; color: var(--muted); margin-top: 6px; }
.chart .bar-count { font-size: 11px; color: var(--muted); margin-bottom: 3px; }

.sub-title { font-size: 14px; font-weight: 600; margin: 22px 0 10px; }

.scroll-x { overflow-x: auto; }

/* ---------- qr ---------- */
.qr-box { text-align: center; }
.qr-box img { width: 240px; height: 240px; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.qr-box .url {
  margin: 14px auto 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
  color: var(--primary);
  font-size: 13px;
}

.qr-actions { display: flex; justify-content: center; gap: 10px; margin-top: 16px; }

/* ---------- list rows ---------- */
.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.list-row:last-child { border-bottom: none; }
.list-row .grow { flex: 1; }
.list-row .tag { font-size: 12px; color: var(--muted); }

/* ---------- toast ---------- */
#toast-wrap {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 9px 18px;
  border-radius: 8px;
  color: #fff;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  animation: toastIn .18s ease-out;
  max-width: 80vw;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: #334155; }

@keyframes toastIn {
  from { transform: translateY(-6px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
