:root {
  --qz-ink: #172522;
  --qz-ink-soft: #40514d;
  --qz-muted: #53645f;
  --qz-green: #276b65;
  --qz-green-deep: #183f3b;
  --qz-green-soft: #dcebe7;
  --qz-red: #ad554e;
  --qz-gold: #ad8242;
  --qz-blue: #3f6685;
  --qz-surface: #ffffff;
  --qz-surface-soft: #f5f8f6;
  --qz-canvas: #edf2ef;
  --qz-border: #cbd9d4;
  --qz-border-strong: #b6c8c1;
  --qz-shadow: 0 8px 24px rgba(25, 54, 49, 0.07);
  --qz-sidebar: 248px;
  --tblr-primary: var(--qz-green);
  --tblr-primary-rgb: 39, 107, 101;
  --tblr-body-bg: var(--qz-canvas);
  --tblr-body-color: var(--qz-ink);
  --tblr-border-color: var(--qz-border);
  --tblr-muted: var(--qz-muted);
}

html { background: var(--qz-canvas); }
body {
  overflow-x: hidden;
  color: var(--qz-ink);
  background: var(--qz-canvas);
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  letter-spacing: 0;
}

a { color: var(--qz-green); }
h1, h2, h3, h4, .navbar-brand { letter-spacing: 0; }
h1, h2, .display-serif {
  font-family: Georgia, "Noto Serif SC", "Songti SC", serif;
  font-weight: 600;
}

/* Authentication */
#login-wrap {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 32px;
  background: var(--qz-canvas);
}
.login-landscape {
  position: fixed;
  inset: auto 0 0;
  height: 26vh;
  min-height: 150px;
  pointer-events: none;
  overflow: hidden;
  opacity: 0.82;
}
.login-landscape::before,
.login-landscape::after {
  content: "";
  position: absolute;
  left: -5%;
  width: 110%;
  border-radius: 50% 50% 0 0;
}
.login-landscape::before {
  bottom: -45%;
  height: 120%;
  background: #c7dcd6;
  transform: rotate(-1deg);
}
.login-landscape::after {
  bottom: -72%;
  height: 130%;
  background: #a9c7bf;
  transform: rotate(1.5deg);
}
.login-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(340px, 420px);
  width: min(980px, 100%);
  min-height: 570px;
  overflow: hidden;
  border: 1px solid rgba(199, 212, 207, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 24px 64px rgba(23, 54, 49, 0.14);
  backdrop-filter: blur(16px);
}
.login-intro {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 54px;
  color: #f5faf8;
  background: var(--qz-green-deep);
  overflow: hidden;
}
.login-intro::after {
  content: "";
  position: absolute;
  right: -15%;
  bottom: -28%;
  width: 78%;
  height: 55%;
  border: 1px solid rgba(218, 235, 229, 0.22);
  border-radius: 50% 50% 0 0;
  box-shadow: 0 -28px 0 rgba(218, 235, 229, 0.05), 0 -56px 0 rgba(218, 235, 229, 0.035);
}
.brand-lockup { position: relative; z-index: 1; display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}
.brand-mark i { font-size: 22px; }
.brand-mark span { font-family: Georgia, "Noto Serif SC", "Songti SC", serif; font-size: 18px; font-weight: 700; }
.brand-name { font-size: 18px; font-weight: 700; }
.login-copy { position: relative; z-index: 1; max-width: 430px; }
.login-kicker, .page-kicker {
  margin-bottom: 10px;
  color: var(--qz-gold);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}
.login-copy h1 { margin: 0 0 18px; color: #fff; font-size: 54px; line-height: 1.12; }
.login-copy p { margin: 0; color: rgba(239, 248, 245, 0.72); font-size: 15px; line-height: 1.9; }
.login-foot { position: relative; z-index: 1; color: rgba(239, 248, 245, 0.52); font-size: 12px; }
.auth-panel { display: flex; flex-direction: column; justify-content: center; padding: 48px; background: rgba(255,255,255,.76); }
.auth-panel-head { margin-bottom: 26px; }
.auth-panel-head h2 { margin: 0 0 7px; font-size: 28px; }
.auth-panel-head p { margin: 0; color: var(--qz-muted); font-size: 13px; }

/* App shell */
#app-wrap { display: none; }
#app-wrap > .page { display: flex; min-height: 100vh; }
.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  width: var(--qz-sidebar);
  min-height: 100vh;
  padding: 18px 14px;
  border-right: 1px solid var(--qz-border);
  color: var(--qz-ink);
  background: rgba(248, 250, 249, 0.94);
  backdrop-filter: blur(18px);
}
.app-sidebar .navbar-brand { min-height: auto; padding: 8px 10px 20px !important; color: var(--qz-ink); }
.app-sidebar .brand-mark { width: 36px; height: 36px; flex-basis: 36px; color: #fff; background: var(--qz-green-deep); }
.app-sidebar .brand-name { font-size: 15px; }
.app-sidebar .navbar-nav { gap: 4px; }
.app-sidebar .nav-link {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--qz-ink-soft);
  transition: color .2s ease, background-color .2s ease, border-color .2s ease, transform .2s ease;
}
.app-sidebar .nav-link:hover { color: var(--qz-ink); background: #fff; border-color: var(--qz-border); transform: translateX(2px); }
.app-sidebar .nav-link.active { color: #fff; background: var(--qz-green-deep); box-shadow: 0 8px 20px rgba(24, 63, 59, .15); }
.app-sidebar .nav-link-icon { width: 1.4rem; height: 1.4rem; margin-right: 10px; color: inherit; font-size: 19px; }
.app-sidebar .nav-glyph { font-family: "Microsoft YaHei", system-ui, sans-serif; font-size: 15px; font-style: normal; font-weight: 700; line-height: 1.4rem; text-align: center; }
.app-sidebar .sidebar-user { margin-top: auto; padding: 12px 8px 4px; border-top: 1px solid var(--qz-border); }
.app-sidebar .avatar { background: var(--qz-green-soft); color: var(--qz-green-deep); }
.app-main { width: calc(100% - var(--qz-sidebar)); margin-left: var(--qz-sidebar); background: transparent; }
.app-main .container-xl { max-width: 1440px; padding: 36px 40px 56px; }

/* Layout and typography */
[id^="page-"] { display: none; }
[id^="page-"].active { display: block; animation: qz-page-enter .42s cubic-bezier(.2,.75,.25,1); }
.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}
.page-heading h2 { margin: 0; font-size: 32px; line-height: 1.2; }
.page-heading-note { color: var(--qz-muted); font-size: 12px; }
.page-heading-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.card {
  border: 1px solid var(--qz-border);
  border-radius: 8px;
  background: var(--qz-surface);
  box-shadow: var(--qz-shadow);
}
.card-header { border-bottom-color: var(--qz-border); background: transparent; }
.card-title { color: var(--qz-ink); }
.stat-card { min-height: 116px; overflow: hidden; }
.stat-card .card-body { position: relative; }
.stat-card .card-body::after {
  content: "";
  position: absolute;
  right: 20px;
  bottom: 14px;
  width: 34px;
  height: 1px;
  background: var(--qz-border-strong);
}
.stat-icon { width: 42px; height: 42px; border-radius: 7px; display: flex; align-items: center; justify-content: center; }
.stat-value { font-family: Georgia, "Noto Serif SC", serif; color: var(--qz-ink); font-size: 30px; line-height: 1; }

.btn { border-radius: 6px; font-weight: 600; letter-spacing: 0; }
.btn .ti { display: inline-flex; width: 1em; height: 1em; align-items: center; justify-content: center; font-size: 1.15em; line-height: 1; }
.btn .ti::before { display: block; width: 1em; height: 1em; color: currentColor; text-align: center; }
.btn-primary { border-color: var(--qz-green); background: var(--qz-green); }
.btn-primary:hover, .btn-primary:focus { border-color: var(--qz-green-deep); background: var(--qz-green-deep); }
.btn-outline-primary { border-color: #5e8d83; color: var(--qz-green-deep); }
.btn-outline-primary:hover { border-color: var(--qz-green); background: var(--qz-green); }
.btn-outline-secondary {
  border-color: #71847e;
  color: #30433e;
  font-weight: 600;
}
.btn-outline-secondary:hover, .btn-outline-secondary:focus-visible {
  border-color: #30433e;
  color: #20332f;
  background: #e7efec;
}
.btn-ghost-primary, .btn-ghost-secondary, .btn-ghost-danger, .btn-ghost-success {
  font-weight: 600;
}
.btn-ghost-primary { color: #1e5d56; }
.btn-ghost-secondary { color: #3f514c; }
.btn-ghost-primary:hover, .btn-ghost-primary:focus-visible,
.btn-ghost-secondary:hover, .btn-ghost-secondary:focus-visible {
  color: #173e39;
  background: #e7efec;
}
.btn-icon:focus-visible, .btn:focus-visible, a:focus-visible {
  outline: 3px solid rgba(39, 107, 101, .35);
  outline-offset: 2px;
}
.text-muted { color: var(--qz-muted) !important; }
.btn-icon { width: 32px; height: 32px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.form-control, .form-select, .input-group-text {
  min-height: 38px;
  border-color: var(--qz-border-strong);
  border-radius: 6px;
  background-color: #fff;
}
.form-control:focus, .form-select:focus { border-color: var(--qz-green); box-shadow: 0 0 0 3px rgba(39, 107, 101, .11); }
.form-label { color: var(--qz-ink-soft); font-size: 12px; font-weight: 700; }
.modal-content { border: 1px solid var(--qz-border); border-radius: 8px; box-shadow: 0 26px 70px rgba(20,45,41,.2); }

.table-shell { overflow: hidden; border: 1px solid var(--qz-border); border-radius: 8px; background: #fff; box-shadow: var(--qz-shadow); }
.table { margin-bottom: 0; }
.table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 12px 14px;
  border-bottom: 1px solid var(--qz-border-strong);
  color: var(--qz-muted);
  background: var(--qz-surface-soft);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
  white-space: nowrap;
}
.table tbody td { padding: 13px 14px; border-bottom-color: #e7eeeb; vertical-align: middle; }
.table tbody tr { transition: background-color .18s ease; }
.table tbody tr:hover { background: #f6faf8; }
.status-badge, .referral-tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}
.referral-tag { margin: 2px 3px 2px 0; color: var(--qz-green-deep); background: var(--qz-green-soft); }
.official-badge { color: #7b561d; background: #f5e9cf; }

/* Referral directory */
.referral-overview {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 22px;
  margin-bottom: 14px;
  padding: 16px 18px;
  border: 1px solid var(--qz-border);
  border-radius: 8px;
  background: rgba(255,255,255,.68);
}
.referral-overview strong { display: block; font-family: Georgia, "Noto Serif SC", serif; font-size: 24px; line-height: 1; }
.referral-overview span { color: var(--qz-muted); font-size: 11px; }
.referral-source { max-width: 430px; }
.referral-filterbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px 180px auto;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--qz-border);
  border-radius: 8px;
  background: #fff;
}
.referral-filterbar .input-icon { position: relative; }
.referral-filterbar .input-icon i { position: absolute; left: 12px; top: 50%; z-index: 2; color: var(--qz-muted); transform: translateY(-50%); }
.referral-filterbar .input-icon input { padding-left: 36px; }
.referral-company { min-width: 170px; }
.referral-company strong { display: block; color: var(--qz-ink); font-size: 14px; }
.referral-code {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 260px;
  padding: 5px 7px;
  border: 1px solid var(--qz-border);
  border-radius: 5px;
  color: var(--qz-green-deep);
  background: #f8fbfa;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}
.referral-actions { display: flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }
.referral-table { min-width: 760px; }
.referral-actions .btn.btn-icon,
.referral-code .btn.btn-icon {
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  font-size: 18px;
}
.referral-action-symbol { display: inline-flex; width: 1em; height: 1em; align-items: center; justify-content: center; color: currentColor; font-family: "Segoe UI Symbol", system-ui, sans-serif; font-size: 15px; font-weight: 700; line-height: 1; }
.referral-code .btn-ghost-primary { color: #18584f; background: #eef6f2; border: 1px solid #9abdb2; }
.referral-code .btn-ghost-primary:hover, .referral-code .btn-ghost-primary:focus-visible { color: #fff; background: #276b65; border-color: #276b65; }
.referral-empty { padding: 58px 20px !important; color: var(--qz-muted); text-align: center; }

.toast-wrap { top: 18px; right: 18px; }
.toast { border-radius: 6px; background: var(--qz-green-deep); box-shadow: var(--qz-shadow); }
.refresh-status.success { color: var(--qz-green); }
.refresh-status.error { color: var(--qz-red); }
.fav-btn { color: var(--qz-gold); }
.extension-copy-btn { min-width: 78px; flex-shrink: 0; }
#page-profile .form-select[multiple] { min-height: 138px; padding: 6px; }
#page-profile .form-select[multiple] option { padding: 7px 9px; border-radius: 4px; }
#page-profile .card-header { min-height: 54px; }
#profile-completion { color: var(--qz-green-deep); font-weight: 650; }

@keyframes qz-page-enter {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 991.98px) {
  #login-wrap { padding: 18px; }
  .login-shell { grid-template-columns: 1fr; width: min(520px, 100%); }
  .login-intro { min-height: 210px; padding: 30px; }
  .login-copy h1 { font-size: 38px; }
  .login-copy p, .login-foot { display: none; }
  .auth-panel { padding: 30px; }
  #app-wrap > .page { display: block; }
  .app-sidebar { position: sticky; width: 100%; min-height: auto; height: auto; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--qz-border); }
  .app-sidebar > .d-flex { width: 100%; min-width: 0; flex-direction: row !important; align-items: center; gap: 10px; }
  .app-sidebar .navbar-brand { flex: 0 0 auto; padding: 0 6px !important; }
  .app-sidebar .brand-name { display: none; }
  .app-sidebar .navbar-nav { min-width: 0; flex: 1; flex-direction: row; flex-wrap: nowrap; overflow-x: auto; padding: 2px; scrollbar-width: none; }
  .app-sidebar .navbar-nav::-webkit-scrollbar { display: none; }
  .app-sidebar .nav-item { flex: 0 0 auto; }
  .app-sidebar .nav-link { min-height: 40px; padding: 8px 10px; }
  .app-sidebar .nav-link:hover { transform: none; }
  .app-sidebar .nav-link-icon { margin: 0; }
  .app-sidebar .nav-link-title { display: none; }
  .app-sidebar .sidebar-user { flex: 0 0 auto; margin: 0; padding: 0 0 0 8px; border: 0; }
  .app-sidebar .sidebar-user .avatar { display: none; }
  .app-sidebar .sidebar-user .flex-1 { display: none; }
  .app-main { width: 100%; margin-left: 0; }
  .app-main .container-xl { padding: 26px 20px 42px; }
  .referral-filterbar { grid-template-columns: 1fr 1fr; }
  .referral-filterbar .input-icon { grid-column: 1 / -1; }
}

@media (max-width: 575.98px) {
  #login-wrap { align-items: flex-start; padding: 0; }
  .login-shell { min-height: 100vh; border: 0; border-radius: 0; }
  .login-intro { min-height: 168px; padding: 24px; }
  .login-copy h1 { margin: 0; font-size: 31px; }
  .auth-panel { justify-content: flex-start; padding: 28px 22px 40px; }
  .page-heading { align-items: flex-start; flex-direction: column; margin-bottom: 18px; }
  .page-heading h2 { font-size: 27px; }
  .page-heading-actions { width: 100%; justify-content: flex-start; }
  .app-main .container-xl { padding: 22px 14px 36px; }
  .referral-overview { grid-template-columns: 1fr 1fr; }
  .referral-source { grid-column: 1 / -1; }
  .referral-filterbar { grid-template-columns: 1fr; }
  .referral-filterbar .input-icon { grid-column: auto; }
  .extension-token-group { flex-wrap: wrap; }
  .extension-token-group .form-control { flex-basis: 100%; border-radius: 6px !important; margin-bottom: 8px; }
  .extension-token-group .btn { flex: 1; border-radius: 6px !important; }
  .table tbody td, .table thead th { padding: 11px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
