:root {
  --bg: #f4f7fb;
  --card: #fff;
  --text: #1a1a1a;
  --muted: #8c8c8c;
  --line: #eef0f4;
  --primary: #1677ff;
  --danger: #ff4d4f;
  --ok: #52c41a;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
.login-page {
  height: 100vh;
  width: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #e8f1ff, #f4f7fb);
}
.login-card {
  width: 400px;
  max-width: calc(100vw - 48px);
  background: #fff;
  border-radius: 16px;
  padding: 36px 32px 28px;
  box-shadow: 0 10px 30px rgba(22,119,255,.08);
}
.logo { width: 56px; height: 56px; border-radius: 14px; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; margin: 0 auto 12px; }
.login-card h1 { text-align: center; color: var(--primary); margin: 0 0 4px; }
.sub { text-align: center; color: var(--muted); margin: 0 0 24px; }
.login-card label { display: block; margin: 14px 0 8px; font-size: 14px; }
.login-card input { width: 100%; }
.login-card label.login-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0 0;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  font-weight: 400;
}
.login-remember input[type=checkbox] {
  width: 16px;
  height: 16px;
}
#login-btn {
  display: block;
  width: 100%;
  margin-top: 18px;
}
label { display: block; margin: 12px 0 6px; font-size: 14px; }
input:not([type=checkbox]), select { width: 100%; height: 42px; border: 1px solid #e5e5e5; border-radius: 8px; padding: 0 12px; font-size: 14px; }
input[type=checkbox] {
  width: 16px;
  height: 16px;
  min-width: 16px;
  margin: 0;
  padding: 0;
  border: 1px solid #d9d9d9;
  border-radius: 3px;
  accent-color: var(--primary);
  flex-shrink: 0;
  cursor: pointer;
}
.btn { height: 42px; border: 0; border-radius: 8px; background: var(--primary); color: #fff; cursor: pointer; font-weight: 600; padding: 0 16px; }
.btn.ghost { background: #fff; color: var(--danger); border: 1px solid #ffccc7; }
.btn.small { height: 30px; font-size: 12px; padding: 0 10px; margin-right: 6px; }
.btn.warn { background: #fa8c16; }
.btn.danger { background: var(--danger); }
.error { color: var(--danger); min-height: 20px; margin-top: 10px; font-size: 13px; }
.app {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}
.side {
  width: 228px;
  flex-shrink: 0;
  height: 100vh;
  overflow: auto;
  background: linear-gradient(180deg, #141c2b 0%, #0d1320 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 22px 14px 16px;
}
.side-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .2px;
  padding: 2px 8px 22px;
}
.side-brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, #3b82f6, #1677ff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  box-shadow: 0 6px 14px rgba(22,119,255,.28);
}
.side nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #9aa8bc;
  text-decoration: none;
  padding: 10px 12px 10px 14px;
  border-radius: 10px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: background .18s ease, color .18s ease;
}
.side nav a::after {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-top: 1.5px solid currentColor;
  transform: rotate(45deg);
  opacity: .38;
  flex-shrink: 0;
  margin-left: 8px;
  transition: opacity .18s ease, transform .18s ease;
}
.side nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side nav a:hover::after { opacity: .75; transform: rotate(45deg) translate(1px, -1px); }
.side nav a.active {
  background: rgba(22,119,255,.16);
  color: #fff;
  box-shadow: inset 3px 0 0 #1677ff;
}
.side nav a.active::after { opacity: .9; }
.side-user {
  margin-top: auto;
  padding: 16px 8px 0;
  border-top: 1px solid rgba(255,255,255,.06);
}
.side-user-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.side-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(22,119,255,.2);
  color: #8eb6ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}
#side-name { font-size: 13px; color: #e8eef7; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user .muted { color: #7d8898; }
#logout-btn {
  display: block;
  width: 100%;
  height: 34px;
  margin-top: 14px;
  border: 0;
  border-radius: 8px;
  background: rgba(255,255,255,.04);
  color: #8b95a5;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .18s ease, color .18s ease;
}
#logout-btn:hover {
  background: rgba(255,255,255,.08);
  color: #d5dbe6;
}
.muted { color: var(--muted); font-size: 12px; }
.main {
  flex: 1;
  min-width: 0;
  height: 100vh;
  padding: 22px 24px;
  overflow: auto;
}
.page { min-height: 0; max-width: 100%; }
.panel canvas { max-height: 260px; width: 100% !important; }
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  min-width: 0;
}
.page-head h2 {
  margin: 0;
  flex: 0 0 auto;
  white-space: nowrap;
  font-size: 22px;
}
.page-head .row {
  flex: 1;
  min-width: 0;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.sub-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin: 24px 0 12px;
  min-width: 0;
}
.sub-head h3 {
  margin: 0;
  flex: 0 0 auto;
  white-space: nowrap;
  font-size: 16px;
}
.sub-head .row {
  flex: 1;
  min-width: 0;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.row { display: flex; gap: 8px; align-items: center; }
.row input, .row select { width: auto; min-width: 140px; max-width: 100%; }
.cards { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.cards.mini { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: var(--card); border-radius: 12px; padding: 16px; min-width: 0; }
.card.clickable { cursor: pointer; }
.card.clickable.on { outline: 2px solid var(--primary); }
.card .n { font-size: 26px; font-weight: 700; margin-top: 6px; word-break: break-all; }
.card .l { color: var(--muted); font-size: 13px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; min-width: 0; }
.panel { background: var(--card); border-radius: 12px; padding: 16px; min-width: 0; overflow: hidden; }
.panel h3 { margin: 0 0 12px; font-size: 15px; }
.rank-list { overflow: visible; }
.rank-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
}
.rank-row:last-child { border-bottom: 0; }
.rank-no {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 700;
  background: #f5f5f5;
  color: #8c8c8c;
}
.rank-no.rank-1 { background: #fff7e6; color: #d48806; }
.rank-no.rank-2 { background: #f5f5f5; color: #595959; }
.rank-no.rank-3 { background: #fff2e8; color: #d46b08; }
.rank-info { flex: 1; min-width: 0; }
.rank-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.rank-num { text-align: right; flex-shrink: 0; }
.rank-num .n { font-size: 18px; font-weight: 700; line-height: 1.2; }
.rank-num .l { font-size: 12px; color: var(--muted); }
.rank-empty { color: var(--muted); font-size: 13px; padding: 24px 0; text-align: center; }
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.chip {
  height: 32px;
  border: 1px solid #d9d9d9;
  background: #fff;
  border-radius: 16px;
  padding: 0 14px;
  cursor: pointer;
  color: #595959;
  font-size: 13px;
}
.chip.on { background: #e6f7ff; border-color: #1677ff; color: #1677ff; }
.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow: auto;
  background: var(--card);
  border-radius: 12px;
}
table { width: max-content; min-width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { background: #fafafa; color: #595959; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; }
.tag.ok { background: #f6ffed; color: #52c41a; }
.tag.off { background: #f5f5f5; color: #8c8c8c; }
.tag.bad { background: #fff2f0; color: #ff4d4f; }
.tag.trial { background: #fff7e6; color: #fa8c16; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 12px; word-break: break-all; }
.form-card {
  max-width: 880px;
  background: #fff;
  padding: 24px 28px 28px;
  border-radius: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 24px;
}
.form-item { min-width: 0; }
.form-item label { margin: 10px 0 6px; }
.form-item-country input { margin-bottom: 8px; }
.form-item #add-country-search { margin-bottom: 8px; }
.form-item-full, #add-submit { grid-column: 1 / -1; }
.form-card .btn {
  width: auto;
  min-width: 168px;
  margin-top: 18px;
  justify-self: start;
}
.dialog { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 20; }
.dialog-card { width: 520px; max-width: calc(100vw - 32px); max-height: 86vh; overflow: auto; background: #fff; border-radius: 12px; padding: 20px; }
.dialog-card h3 { margin: 0 0 16px; }
.dialog-card > p { margin: 0 0 12px; }
.dialog-card input:not([type=checkbox]),
.dialog-card select {
  display: block;
  margin-bottom: 12px;
}
.dialog-actions { display: flex; gap: 12px; margin-top: 20px; }
.dialog-actions .btn { flex: 1; width: auto; margin: 0; white-space: nowrap; }
.toast { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); padding: 10px 16px; border-radius: 8px; z-index: 30; color: #fff; }
.toast.ok { background: #52c41a; }
.toast.err { background: #ff4d4f; }
.check-list { max-height: 220px; overflow: auto; border: 1px solid #eee; border-radius: 8px; padding: 8px; }
.check-list label, .check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 4px 0;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.perm-title { margin: 16px 0 8px; font-size: 13px; font-weight: 600; color: #595959; }
.perm-grid { display: flex; flex-wrap: wrap; gap: 8px 18px; }
@media (max-width: 1100px) {
  .cards, .cards.mini, .grid-2 { grid-template-columns: 1fr 1fr; }
  .side { width: 196px; }
  .form-card { grid-template-columns: 1fr; max-width: 560px; }
}
