:root {
  color-scheme: dark;
  --bg: #111416;
  --panel: #191d21;
  --panel-2: #20262b;
  --text: #edf2f4;
  --muted: #9ca8ae;
  --line: #30383f;
  --accent: #4fb7a8;
  --accent-2: #f2c14e;
  --danger: #e45d5d;
  --field-bg: #0d1012;
  --toast-bg: var(--panel);
  --toast-text: var(--text);
  --toast-line: var(--line);
  --toast-shadow: rgba(0, 0, 0, 0.28);
}

body.theme-light {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-2: #f3f6fa;
  --text: #1e293b;
  --muted: #64748b;
  --line: #d9e2ef;
  --accent: #11998e;
  --accent-2: #d19b1d;
  --danger: #dc4f4f;
  --field-bg: #ffffff;
  --toast-bg: #ffffff;
  --toast-text: #1e293b;
  --toast-line: #d9e2ef;
  --toast-shadow: rgba(15, 23, 42, 0.12);
}

body.theme-dayblue {
  color-scheme: light;
  --bg: #eef4fb;
  --panel: #ffffff;
  --panel-2: #f6f9fd;
  --text: #0f172a;
  --muted: #51617a;
  --line: #d6e0ef;
  --accent: #1483d8;
  --accent-2: #d49b2a;
  --danger: #dc4f4f;
  --field-bg: #ffffff;
  --toast-bg: #ffffff;
  --toast-text: #0f172a;
  --toast-line: #d6e0ef;
  --toast-shadow: rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 238px 1fr;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei UI", "Segoe UI", sans-serif;
}

[hidden] { display: none !important; }

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(10, 12, 14, 0.94);
}

.login-screen.hidden {
  display: none;
}

.login-panel {
  width: min(420px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  display: grid;
  gap: 14px;
}

.login-panel h1 {
  font-size: 24px;
}

.login-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.login-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.login-tabs button {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

.login-tabs button.active {
  background: var(--accent);
  color: #061311;
  border-color: transparent;
}

#loginForm,
#registerForm {
  display: grid;
  gap: 14px;
}

.login-error {
  min-height: 20px;
  color: var(--danger);
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 1px solid transparent;
  background: var(--accent);
  color: #061311;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

button:hover { filter: brightness(1.05); }

button:disabled {
  cursor: not-allowed;
  opacity: .55;
  filter: none;
}

input, select, textarea {
  width: 100%;
  background: var(--field-bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  min-height: 36px;
  padding: 8px 10px;
  outline: none;
}

input[type="checkbox"] {
  width: 14px;
  height: 14px;
  min-width: 14px;
  min-height: 14px;
  padding: 0;
  margin: 0;
  accent-color: var(--accent);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

.wide {
  grid-column: 1 / -1;
}

input[readonly] {
  color: var(--muted);
  border-color: #263038;
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  background: #15191c;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #071210;
  font-weight: 900;
}

.brand strong { display: block; }
.brand span { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }

nav {
  display: grid;
  gap: 8px;
}

.nav {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--muted);
  border-color: transparent;
  font-weight: 600;
}

.nav.active {
  background: var(--panel-2);
  color: var(--text);
  border-color: var(--line);
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

h1, h2, p { margin: 0; }
h1 { font-size: 26px; }
h2 { font-size: 18px; }
p { color: var(--muted); margin-top: 6px; }

.panel-count {
  margin-left: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.auth {
  display: grid;
  grid-template-columns: auto auto;
  gap: 8px;
  align-items: center;
}

.auth-label,
.target-user span,
#currentUserLabel {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.target-user {
  display: grid;
  grid-template-columns: auto minmax(180px, 240px);
  gap: 8px;
  align-items: center;
  margin-left: auto;
}

.notice-tools {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  min-width: 38px;
  width: 38px;
  padding: 0;
  position: relative;
  display: inline-grid;
  place-items: center;
}

.icon-button.has-unread {
  border-color: rgba(79, 183, 168, 0.75);
  box-shadow: 0 0 0 2px rgba(79, 183, 168, 0.16);
}

.bell-icon {
  width: 18px;
  height: 18px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#noticeUnreadBadge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
}

.notice-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 30;
  width: min(360px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
  overflow: hidden;
}

.notice-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.notice-head button {
  min-height: 28px;
  padding: 0 10px;
}

.notice-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.notice-list {
  max-height: 320px;
  overflow: auto;
}

.notice-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.notice-item-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.notice-item-head strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.notice-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.notice-delete-one {
  min-height: 26px;
  padding: 0 8px;
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
  flex: 0 0 auto;
}

.notice-item.is-read {
  opacity: .62;
}

.notice-item p {
  margin-top: 6px;
  color: var(--text);
  line-height: 1.45;
}

.notice-item small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
}

.notice-mail-one {
  min-height: 26px;
  padding: 0 8px;
  color: var(--accent);
  border-color: var(--accent);
  background: transparent;
  flex: 0 0 auto;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0,0,0,.58);
}

.modal-card {
  width: min(620px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

#noticeComposer .modal-card {
  width: min(560px, calc(100vw - 32px));
}

#noticeComposer .form-grid.notice-composer-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

#noticeComposer .form-grid.notice-composer-grid .wide {
  grid-column: 1 / -1;
}

#noticeComposer .toggle-line.notice-email-toggle {
  align-items: center;
  min-height: 36px;
  grid-column: 1 / -1;
}

#noticeComposer .button-pair {
  justify-content: flex-end;
}

#noticeComposer input,
#noticeComposer select,
#noticeComposer textarea {
  min-width: 0;
}

#noticeComposer textarea {
  width: 100%;
  max-width: 100%;
  min-height: 150px;
  max-height: min(46vh, 360px);
  resize: vertical;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-head button {
  min-width: 36px;
  width: 36px;
  padding: 0;
}

.notice-popup-overlay {
  z-index: 60;
}

.unread-notice-card {
  width: min(680px, 100%);
  max-height: min(78vh, 760px);
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  gap: 12px;
  padding: 28px 32px 20px;
}

.unread-notice-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.unread-notice-icon,
.unread-notice-pill {
  display: inline-grid;
  place-items: center;
  min-height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: #061311;
  font-weight: 800;
}

.unread-notice-icon {
  width: 28px;
}

.unread-notice-pill {
  padding: 0 10px;
  font-size: 12px;
}

.unread-notice-card h2 {
  font-size: 24px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.unread-notice-card small {
  color: var(--muted);
}

.unread-notice-content {
  overflow: auto;
  white-space: pre-wrap;
  line-height: 1.75;
  color: var(--text);
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.unread-notice-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.invite-payment-card {
  width: min(540px, 100%);
}

.invite-payment-summary {
  display: grid;
  gap: 12px;
}

.invite-pay-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.invite-pay-grid > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel-2);
}

.invite-pay-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.invite-pay-grid strong {
  display: block;
  font-size: 18px;
  color: var(--text);
  overflow-wrap: anywhere;
}

.invite-pay-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.invite-payment-actions {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.invite-payment-actions button {
  width: 100%;
}

.pay-route-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.gateway-cards {
  display: grid;
  gap: 18px;
  margin-top: 12px;
}

.gateway-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  background: var(--panel);
}

.gateway-card .panel-head {
  min-height: 42px;
  margin: 0;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}

.gateway-card .panel-head h2 {
  font-size: 15px;
}

.pay-gateway-body {
  display: grid;
  gap: 14px;
  padding: 18px 16px;
}

.pay-gateway-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 14px;
  align-items: start;
}

.pay-enable-line,
.pay-check-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  color: var(--text);
  font-weight: 800;
}

.pay-field {
  min-width: 0;
}

.pay-field-textarea textarea {
  min-height: 76px;
  resize: vertical;
}

.pay-gateway-actions {
  display: flex;
  justify-content: flex-start;
}

.pay-gateway-actions button::before {
  content: "✓";
  margin-right: 7px;
}

.template-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.template-status {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

body.is-template-mode .template-status {
  border-color: rgba(79, 183, 168, 0.45);
  background: rgba(79, 183, 168, 0.12);
  color: var(--text);
}

.popup-settings {
  display: grid;
  gap: 18px;
}

.popup-settings textarea {
  resize: vertical;
  min-height: 84px;
}

.popup-admin-block {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: color-mix(in srgb, var(--panel-2) 62%, transparent);
}

.popup-admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.popup-admin-head h3 {
  margin: 0;
  font-size: 15px;
}

.popup-config-list {
  display: grid;
  gap: 12px;
}

.popup-config-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px auto;
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
}

.popup-config-fields {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 10px;
}

.popup-config-fields .wide {
  grid-column: 1 / -1;
}

.popup-preview {
  width: 132px;
  min-height: 132px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fff;
  color: #64748b;
  display: grid;
  place-items: center;
  padding: 8px;
  text-align: center;
  font-size: 12px;
  overflow: hidden;
}

.popup-preview img {
  max-width: 100%;
  max-height: 116px;
  object-fit: contain;
  display: block;
}

.popup-row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.popup-empty {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  text-align: center;
}

.status {
  display: none !important;
  visibility: hidden !important;
  height: 0 !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
}

.toast-stack {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2147483000;
  display: grid;
  gap: 8px;
  width: min(320px, calc(100vw - 24px));
  pointer-events: none;
  isolation: isolate;
}

.toast {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) 18px;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  padding: 8px 9px;
  overflow: hidden;
  border: 1px solid var(--toast-line);
  border-radius: 6px;
  background: var(--toast-bg);
  box-shadow: 0 8px 24px var(--toast-shadow);
  color: var(--toast-text);
  transform: translateX(10px);
  opacity: 0;
  animation: toast-in 180ms ease forwards;
  pointer-events: auto;
}

.toast-icon {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #37c789;
  color: #09201a;
  font-size: 11px;
  font-weight: 900;
}

.toast.error .toast-icon {
  background: #ff5d5d;
  color: #fff;
}

.toast.warn .toast-icon {
  background: #f7c948;
  color: #111416;
}

.toast-message {
  line-height: 1.35;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-weight: 700;
  font-size: 13px;
}

.toast-close {
  width: 18px;
  min-height: 18px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  font-weight: 400;
  line-height: 1;
}

.toast-close:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--panel-2) 78%, transparent);
}

.toast.removing {
  animation: toast-out 160ms ease forwards;
}

.client-build-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147482500;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(5, 8, 10, 0.68);
}

.client-build-overlay.show {
  display: grid;
}

.client-build-dialog {
  width: min(460px, calc(100vw - 32px));
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: #151a1d;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.36);
  padding: 26px;
  display: grid;
  gap: 14px;
  justify-items: center;
  text-align: center;
}

.client-build-ring {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(79, 183, 168, 0.12);
  box-shadow: inset 0 0 0 1px rgba(79, 183, 168, 0.2);
}

.client-build-ring span {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(79, 183, 168, 0.24);
  border-top-color: var(--accent);
  animation: build-spin 1200ms linear infinite;
}

.client-build-overlay.done .client-build-ring span,
.client-build-overlay.error .client-build-ring span {
  animation: none;
  border-color: var(--accent);
  border-top-color: var(--accent);
}

.client-build-overlay.done .client-build-ring span::after {
  content: "✓";
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--accent);
  font-weight: 900;
}

.client-build-overlay.error .client-build-ring {
  background: rgba(228, 93, 93, 0.12);
}

.client-build-overlay.error .client-build-ring span {
  border-color: var(--danger);
}

.client-build-overlay.error .client-build-ring span::after {
  content: "!";
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--danger);
  font-weight: 900;
}

.client-build-dialog h2 {
  font-size: 20px;
}

.client-build-dialog p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.client-build-meter {
  width: 100%;
  height: 9px;
  border-radius: 999px;
  overflow: hidden;
  background: #0c1012;
  border: 1px solid var(--line);
}

.client-build-meter i {
  display: block;
  width: 12%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #74d6c8);
  transition: width 360ms ease;
}

.client-build-meta {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

#clientBuildClose {
  min-width: 90px;
}

@keyframes build-spin {
  to { transform: rotate(360deg); }
}

@keyframes toast-in {
  to { transform: translateX(0); opacity: 1; }
}

@keyframes toast-out {
  to { transform: translateX(18px); opacity: 0; }
}

.view { display: none; }
.view.show { display: grid; gap: 18px; }

#view-overview.show {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

#view-overview > .panel:first-child,
#appLoginPanel,
#appUpdatePanel,
#view-overview > .stats,
.overview-savebar {
  grid-column: 1 / -1;
}

#appPropertyPanel .form-grid {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

#appLoginPanel {
  display: none;
}

body.is-super-admin #appLoginPanel {
  display: block;
}

.overview-savebar {
  display: flex;
  justify-content: flex-end;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head h2 {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  overflow-wrap: anywhere;
}

.collapsible-panel.is-collapsed .panel-head {
  margin-bottom: 0;
}

.collapsible-panel.is-collapsed .panel-head > button:not(.panel-collapse-toggle) {
  display: none;
}

.panel-collapse-toggle {
  flex: 0 0 auto;
  min-height: 30px;
  padding: 0 10px;
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--text);
  font-size: 12px;
}

.panel-collapse-toggle::before {
  content: "▸";
  display: inline-block;
  margin-right: 5px;
}

.collapsible-panel:not(.is-collapsed) .panel-collapse-toggle::before {
  content: "▾";
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
}

.form-grid.compact {
  grid-template-columns: 1.1fr 1.1fr 1fr 1.3fr 140px 2fr;
}

.manage-grid {
  display: grid;
  grid-template-columns: 170px minmax(180px, 1fr) minmax(220px, 1.2fr) minmax(180px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.button-pair {
  display: flex;
  gap: 8px;
  align-items: end;
  flex-wrap: wrap;
}

.button-pair button {
  white-space: nowrap;
}

.batch-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  padding: 10px 0 14px;
}

.checkline {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  min-height: 36px;
}

.checkline input,
.user-check {
  width: 14px;
  min-height: 14px;
}

.user-card-list {
  display: grid;
  gap: 12px;
}

.user-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #12171a;
  overflow: hidden;
}

.user-card-main {
  display: grid;
  grid-template-columns: auto 34px 42px minmax(180px, 1fr) auto auto auto minmax(220px, auto);
  gap: 10px;
  align-items: center;
  padding: 12px;
}

.user-expand {
  width: 34px;
  padding: 0;
  background: var(--panel-2);
  color: var(--text);
  border-color: var(--line);
}

.user-avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #071210;
  font-weight: 900;
}

.user-summary {
  min-width: 0;
}

.user-summary strong,
.user-summary span,
.user-summary small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-summary span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.user-summary small {
  margin-top: 3px;
  color: #7f8d94;
  font-size: 12px;
}

.user-card-detail {
  border-top: 1px solid var(--line);
  padding: 14px;
  background: var(--panel);
}

.card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 6px;
  border: 1px solid rgba(79, 183, 168, 0.35);
  color: var(--text);
  background: rgba(79, 183, 168, 0.12);
  white-space: nowrap;
  font-size: 12px;
  font-weight: 700;
}

.danger-pill {
  border-color: rgba(228, 93, 93, 0.45);
  background: rgba(228, 93, 93, 0.12);
}

.muted-pill {
  border-color: var(--line);
  background: var(--panel-2);
  color: var(--muted);
}

.inline-balance {
  display: grid;
  grid-template-columns: auto 96px auto;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.inline-balance input {
  min-height: 30px;
  padding: 5px 8px;
}

.inline-balance button {
  min-height: 30px;
  padding: 0 10px;
  white-space: nowrap;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.toggle-line span {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  color: var(--text);
}

.toggle-line input[type="checkbox"] {
  width: 14px;
  min-height: 14px;
}

.wide { grid-column: 1 / -1; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.stats div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.stats strong {
  display: block;
  font-size: 30px;
}

.stats span { color: var(--muted); }

.search { max-width: 320px; }

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1320px;
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  vertical-align: top;
}

th {
  color: var(--muted);
  text-align: left;
  background: #14181b;
  font-size: 13px;
}

td small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

.target-note {
  min-height: 18px;
  font-size: 12px;
}

.target-input {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sort-input {
  width: 72px;
  min-width: 72px;
  text-align: center;
}

.button-filters {
  display: grid;
  grid-template-columns: minmax(130px, 180px) minmax(130px, 180px) minmax(130px, 170px) minmax(220px, 1fr);
  gap: 10px;
  align-items: center;
  width: min(720px, 100%);
}

.button-filters .search {
  width: 100%;
}

.icon-field {
  display: grid;
  grid-template-columns: 54px minmax(220px, 1fr);
  gap: 10px;
  align-items: center;
  min-width: 290px;
}

.icon-preview {
  width: 52px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  user-select: none;
}

.icon-preview img {
  max-width: 42px;
  max-height: 28px;
  object-fit: contain;
}

.icon-field input {
  min-width: 220px;
}

td.actions {
  width: 260px;
  min-width: 260px;
}

td.actions button {
  margin: 0 6px 6px 0;
  white-space: nowrap;
}

tr.row-highlight {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: rgba(79, 183, 168, .12);
  transition: background .25s ease, outline-color .25s ease;
}

.button-disabled-row {
  opacity: 0.58;
}

.button-disabled-row input,
.button-disabled-row select {
  color: var(--muted);
}

.muted-action {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.script-target-control {
  display: grid;
  gap: 8px;
}

.custom-script-input {
  min-width: 260px;
}

.user-endpoint {
  min-width: 360px;
}

.invite-create {
  grid-template-columns: minmax(180px, 0.9fr) 112px 112px 136px;
  gap: 10px;
  margin-bottom: 12px;
}

.invite-create label {
  font-size: 12px;
}

.invite-create input {
  min-height: 32px;
  padding: 6px 9px;
}

.invite-table table {
  min-width: 1020px;
}

.invite-table th,
.invite-table td {
  padding: 7px 10px;
  font-size: 13px;
  vertical-align: middle;
}

.invite-table th:first-child,
.invite-table td:first-child {
  width: 42px;
  text-align: center;
}

.invite-table .actions {
  width: 220px;
  min-width: 220px;
}

.invite-table .actions button {
  min-height: 30px;
  padding: 0 10px;
  margin-bottom: 0;
}

.invite-code {
  min-width: 150px;
  max-width: 210px;
  min-height: 30px;
  padding: 5px 8px;
  font-size: 13px;
}

.invite-result-card {
  width: min(620px, calc(100vw - 32px));
}

.invite-result-list {
  display: grid;
  gap: 10px;
  max-height: 45vh;
  overflow: auto;
}

.invite-result-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.invite-result-row input {
  min-width: 0;
}

.invite-result-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 14px;
  flex-wrap: wrap;
}

.invite-result-actions button,
.invite-result-row button {
  min-height: 34px;
}

.invite-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 6px;
  border: 1px solid rgba(79, 183, 168, .42);
  background: rgba(79, 183, 168, .12);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.invite-badge.is-inactive,
.invite-badge.is-used {
  border-color: rgba(228, 93, 93, .55);
  background: rgba(228, 93, 93, .12);
}

.invite-badge.is-unused {
  color: #bff5ea;
}

.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

#jsonEditor {
  min-height: 62vh;
  resize: vertical;
  font-family: Consolas, "Cascadia Mono", monospace;
  line-height: 1.45;
}

.json-permission-panel {
  margin-bottom: 0;
}

.permission-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.permission-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #12171a;
}

.permission-item input {
  width: auto;
  min-height: 0;
}

.permission-item strong,
.permission-item small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.permission-item small {
  margin-top: 2px;
  color: var(--muted);
}

@media (max-width: 900px) {
  body {
    display: block;
    min-height: 100vh;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 15;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px;
  }

  .brand {
    margin-bottom: 12px;
  }

  nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav {
    flex: 0 0 auto;
    width: auto;
    min-width: 76px;
    text-align: center;
    padding: 0 12px;
  }

  main {
    padding: 14px;
  }

  .topbar {
    display: grid;
    gap: 12px;
  }

  .topbar > div:first-child {
    min-width: 0;
  }

  h1 {
    font-size: 22px;
  }

  .target-user {
    grid-template-columns: 1fr;
    margin-left: 0;
  }

  .button-filters {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .auth {
    grid-template-columns: 1fr auto;
  }

  .form-grid,
  .form-grid.compact,
  .manage-grid,
  .invite-create,
  .template-actions {
    grid-template-columns: 1fr;
  }

  .template-actions {
    display: grid;
  }

  .template-actions button,
  .template-status {
    width: 100%;
  }

  .user-card-main {
    grid-template-columns: auto 34px 38px minmax(0, 1fr);
  }

  .user-card-main .pill {
    grid-column: span 2;
  }

  .inline-balance {
    grid-column: 1 / -1;
    grid-template-columns: auto minmax(96px, 1fr) auto;
  }

  .panel {
    padding: 12px;
  }

  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .stats {
    grid-template-columns: 1fr;
  }

  .search {
    max-width: none;
  }

  .button-pair {
    align-items: stretch;
  }

  .button-pair button {
    flex: 1 1 120px;
  }

  .toast-stack {
    top: 10px;
    right: 10px;
    left: 10px;
    width: auto;
  }

  table {
    min-width: 860px;
  }

  .user-endpoint {
    min-width: 260px;
  }

  .pay-route-grid,
  .pay-gateway-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .popup-config-row {
    grid-template-columns: 1fr;
  }

  .popup-config-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .popup-preview {
    width: 100%;
    min-height: 148px;
  }

  .popup-preview img {
    max-height: 132px;
  }

  .popup-row-actions {
    justify-content: stretch;
  }

  .popup-row-actions button {
    flex: 1 1 120px;
  }
}

@media (max-width: 520px) {
  .login-panel {
    width: calc(100vw - 20px);
    padding: 16px;
  }

  .login-tabs {
    grid-template-columns: 1fr;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .auth {
    grid-template-columns: 1fr;
  }

  .panel-head button,
  .auth button {
    width: 100%;
  }

  .pay-route-grid,
  .pay-gateway-grid {
    grid-template-columns: 1fr;
  }

  .pay-gateway-actions button {
    width: 100%;
  }

  .popup-config-fields {
    grid-template-columns: 1fr;
  }

  .popup-admin-head button {
    width: 100%;
  }
}

.endpoint {
  margin-top: 12px;
  padding: 12px;
  background: #0d1012;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: Consolas, "Cascadia Mono", monospace;
  word-break: break-all;
}

.note {
  color: var(--muted);
  line-height: 1.7;
}

pre {
  overflow: auto;
  background: #0d1012;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
}

@media (max-width: 980px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .topbar { align-items: stretch; flex-direction: column; }
  .auth, .target-user { grid-template-columns: 1fr; }
  #view-overview.show,
  #appPropertyPanel .form-grid,
  .form-grid, .form-grid.compact, .manage-grid, .stats { grid-template-columns: 1fr; }
}

/* Collapsible app sidebar */
body {
  grid-template-columns: 238px minmax(0, 1fr);
  transition: grid-template-columns 180ms ease;
}

body.sidebar-collapsed {
  grid-template-columns: 66px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  transition: width 180ms ease, padding 180ms ease;
}

.sidebar-toggle {
  width: 34px;
  min-height: 34px;
  padding: 0;
  margin: 0 0 14px;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--text);
  border-color: transparent;
}

.sidebar-toggle:hover,
.sidebar-toggle:focus {
  background: var(--panel-2);
  border-color: var(--line);
}

.brand > div:last-child,
.nav-text {
  min-width: 0;
  opacity: 1;
  transform: translateX(0);
  transition: opacity 140ms ease, transform 140ms ease;
}

.nav {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 0 12px;
  overflow: hidden;
}

.nav-icon {
  width: 28px;
  min-width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-weight: 900;
  color: var(--text);
}

.nav.active .nav-icon {
  background: rgba(79, 183, 168, 0.16);
  color: var(--accent);
}

body.sidebar-collapsed .sidebar {
  padding-left: 14px;
  padding-right: 14px;
}

body.sidebar-collapsed .brand {
  justify-content: center;
  margin-bottom: 20px;
}

body.sidebar-collapsed .brand > div:last-child,
body.sidebar-collapsed .nav-text {
  width: 0;
  opacity: 0;
  transform: translateX(-8px);
  pointer-events: none;
}

body.sidebar-collapsed .brand-mark {
  width: 36px;
  height: 36px;
}

body.sidebar-collapsed nav {
  gap: 10px;
}

body.sidebar-collapsed .nav {
  grid-template-columns: 28px;
  justify-content: center;
  width: 38px;
  padding: 0 5px;
  border-radius: 10px;
}

body.sidebar-collapsed .nav.active {
  background: var(--panel-2);
}

@media (max-width: 900px) {
  body,
  body.sidebar-collapsed {
    display: grid;
    grid-template-columns: 66px minmax(0, 1fr);
  }

  body.sidebar-open {
    grid-template-columns: 204px minmax(0, 1fr);
  }

  body.sidebar-open .brand > div:last-child,
  body.sidebar-open .nav-text {
    width: auto;
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
  }

  body.sidebar-open .nav {
    grid-template-columns: 28px minmax(0, 1fr);
    justify-content: stretch;
    width: 100%;
    padding: 0 12px;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 16;
    height: 100vh;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    padding: 12px 14px;
  }

  .sidebar-toggle {
    margin-bottom: 14px;
  }

  .brand {
    margin-bottom: 20px;
  }

  nav {
    display: grid;
    overflow: visible;
    padding-bottom: 0;
  }

  main {
    min-width: 0;
    padding: 14px;
  }
}

@media (max-width: 900px) {
  body,
  body.sidebar-collapsed,
  body.sidebar-open {
    display: block;
    grid-template-columns: none;
    padding-left: 0;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: 0;
    height: 100dvh;
    padding: 0;
    border-right: 0;
    border-bottom: 0;
    background: transparent;
    box-shadow: none;
    overflow: visible;
    transition: width 180ms ease, padding 180ms ease;
  }

  body.sidebar-open .sidebar {
    width: min(246px, 82vw);
    padding: 58px 14px 16px;
    border-right: 1px solid var(--line);
    background: #15191c;
    box-shadow: 24px 0 48px rgba(0, 0, 0, 0.42);
  }

  .sidebar .brand,
  .sidebar nav {
    display: none;
  }

  body.sidebar-open .sidebar .brand,
  body.sidebar-open .sidebar nav {
    display: flex;
  }

  body.sidebar-open .sidebar nav {
    display: grid;
  }

  .sidebar-toggle {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 50;
    width: 40px;
    min-height: 40px;
    margin: 0;
    border-color: var(--line);
    background: #15191c;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.34);
  }

  .brand {
    justify-content: flex-start;
    margin-bottom: 18px;
  }

  body.sidebar-collapsed .brand > div:last-child,
  body.sidebar-collapsed .nav-text,
  body.sidebar-open .brand > div:last-child,
  body.sidebar-open .nav-text {
    width: auto;
    opacity: 1;
    transform: none;
    pointer-events: auto;
  }

  nav,
  body.sidebar-collapsed nav {
    display: grid;
    gap: 8px;
    overflow: visible;
  }

  .nav,
  body.sidebar-collapsed .nav,
  body.sidebar-open .nav {
    grid-template-columns: 28px minmax(0, 1fr);
    justify-content: stretch;
    width: 100%;
    min-width: 0;
    padding: 0 12px;
    text-align: left;
  }

  main {
    min-width: 0;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    padding: 58px 14px 14px;
  }

  .panel,
  .form-grid,
  .manage-grid,
  input,
  select,
  textarea,
  button {
    max-width: 100%;
  }

  .topbar {
    display: grid;
    gap: 12px;
  }

  .auth,
  .target-user {
    grid-template-columns: 1fr;
    margin-left: 0;
  }

  .panel-head button,
  .auth button,
  .card-actions button,
  .button-pair button {
    width: 100%;
  }

  .card-actions,
  .button-pair {
    display: grid;
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  #view-users.show {
    gap: 12px;
  }

  #view-users .panel {
    padding: 12px;
    overflow: hidden;
  }

  #view-users .panel-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
    gap: 10px;
  }

  #view-users .panel-head h2 {
    font-size: 18px;
    line-height: 1.35;
  }

  #view-users .panel-head > button:not(.panel-collapse-toggle) {
    min-height: 34px;
  }

  .panel-collapse-toggle {
    width: auto;
    max-width: none;
  }

  .batch-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px 0;
  }

  .batch-bar .checkline,
  .batch-bar .danger {
    grid-column: 1 / -1;
  }

  .user-card-list {
    gap: 10px;
  }

  .user-card-main {
    grid-template-columns: 18px 34px 40px minmax(0, 1fr);
    gap: 8px;
    padding: 10px;
  }

  .user-card-main .pill {
    grid-column: auto;
    min-height: 26px;
    padding: 0 8px;
    font-size: 12px;
  }

  .user-card-main .pill:nth-of-type(1) {
    grid-column: 2 / 4;
  }

  .user-card-main .pill:nth-of-type(2),
  .user-card-main .pill:nth-of-type(3) {
    grid-column: span 2;
  }

  .inline-balance {
    grid-column: 1 / -1;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .user-summary strong,
  .user-summary span,
  .user-summary small {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .user-card-detail {
    padding: 12px;
  }

  .user-endpoint {
    min-width: 0;
  }

  .invite-create {
    margin-bottom: 10px;
  }

  .invite-table {
    border: 0;
    overflow: visible;
  }

  .invite-table table,
  .invite-table thead,
  .invite-table tbody,
  .invite-table tr,
  .invite-table th,
  .invite-table td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .invite-table thead {
    display: none;
  }

  .invite-table tr {
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #12171a;
    overflow: hidden;
  }

  .invite-table td {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    min-height: 42px;
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
    overflow-wrap: anywhere;
  }

  .invite-table td::before {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  .invite-table td:nth-child(1)::before { content: "选择"; }
  .invite-table td:nth-child(2)::before { content: "邀请码"; }
  .invite-table td:nth-child(3)::before { content: "生成时间"; }
  .invite-table td:nth-child(4)::before { content: "状态"; }
  .invite-table td:nth-child(5)::before { content: "是否使用"; }
  .invite-table td:nth-child(6)::before { content: "使用次数"; }
  .invite-table td:nth-child(7)::before { content: "使用记录"; }
  .invite-table td:nth-child(8)::before { content: "操作"; }

  .invite-table td:first-child {
    text-align: left;
  }

  .invite-table td:last-child {
    border-bottom: 0;
  }

  .invite-table .actions {
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
  }

  .invite-table .actions button {
    width: 100%;
    margin: 0 0 8px;
  }

  .invite-table .actions button:last-child {
    margin-bottom: 0;
  }

  .invite-code {
    min-width: 0;
    max-width: 100%;
  }

  .invite-result-row {
    grid-template-columns: 1fr;
  }

  .invite-result-row button,
  .invite-result-actions button {
    width: 100%;
  }
}

/* Final mobile layout overrides */
#view-buttons .form-grid.compact {
  grid-template-columns: repeat(4, minmax(150px, 1fr)) auto auto;
  align-items: end;
}

#view-buttons .form-grid.compact > button {
  width: auto;
  min-width: 112px;
  justify-self: end;
  align-self: end;
}

#view-buttons .panel-head > button {
  width: auto;
  flex: 0 0 auto;
}

@media (max-width: 900px) {
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: start;
    gap: 10px 8px;
  }

  .topbar > div:first-child {
    grid-column: 1 / 2;
    grid-row: 1;
    min-width: 0;
  }

  .notice-tools {
    grid-column: 2 / 3;
    grid-row: 1;
    justify-self: end;
    align-self: start;
  }

  #logoutBtn {
    grid-column: 3 / 4;
    grid-row: 1;
    width: auto;
    min-width: 64px;
    justify-self: end;
    align-self: start;
  }

  .target-user {
    grid-column: 1 / -1;
    grid-row: 2;
    grid-template-columns: 72px minmax(0, 1fr);
    align-items: center;
    margin-left: 0;
  }

  #currentUserLabel {
    grid-column: 1 / -1;
    grid-row: 3;
  }

  #view-buttons .panel-head {
    display: flex;
    flex-direction: row;
    align-items: center;
  }

  #view-buttons .panel-head > button {
    width: auto;
    min-width: 96px;
  }

  #view-buttons .form-grid.compact {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  #view-buttons .form-grid.compact > button {
    width: auto;
    min-width: 112px;
    justify-self: end;
  }

  .invite-table {
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: auto;
  }

  .invite-table table {
    display: table;
    width: 100%;
    min-width: 1040px;
  }

  .invite-table thead {
    display: table-header-group;
  }

  .invite-table tbody {
    display: table-row-group;
  }

  .invite-table tr {
    display: table-row;
    margin-bottom: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    overflow: visible;
  }

  .invite-table th,
  .invite-table td {
    display: table-cell;
    width: auto;
    min-width: 0;
    min-height: 0;
    padding: 7px 10px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
  }

  .invite-table td::before {
    content: none !important;
  }

  .invite-table th:first-child,
  .invite-table td:first-child {
    width: 42px;
    text-align: center;
  }

  .invite-table .actions {
    display: table-cell;
    width: 220px;
    min-width: 220px;
  }

  .invite-table .actions button {
    width: auto;
    margin: 0 6px 6px 0;
  }

  .invite-code {
    min-width: 150px;
    max-width: 210px;
  }
}

@media (max-width: 520px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  #noticeComposer .form-grid.notice-composer-grid {
    grid-template-columns: 1fr;
  }

  .notice-item-head {
    display: grid;
    grid-template-columns: 1fr;
  }

  .notice-item-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .notice-tools {
    grid-column: 2 / 3;
  }

  #logoutBtn {
    grid-column: 2 / 3;
    grid-row: 2;
  }

  .target-user {
    grid-row: 3;
  }

  #currentUserLabel {
    grid-row: 4;
  }

  #openNoticeComposerBtn {
    padding: 0 12px;
  }
}
