:root {
  --bg: #f3f5f8;
  --card: #fff;
  --text: #1a1f2e;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #0f766e;
  --primary-hover: #0d9488;
  --danger: #dc2626;
  --ok: #059669;
  --radius: 10px;
  --shadow: 0 8px 30px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
.muted { color: var(--muted); font-size: 13px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  background: #0b1220;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-weight: 700; letter-spacing: .02em; display: flex; align-items: center; gap: 10px; }
.brand-logo {
  width: 34px;
  height: 34px;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
  padding: 2px;
}
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.main { max-width: 1100px; margin: 0 auto; padding: 18px 16px 40px; }

.hero-tip {
  background: linear-gradient(135deg, #ecfdf5, #f0f9ff);
  border: 1px solid #cce7df;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
  color: #134e4a;
  line-height: 1.7;
}

.portal-card {
  display: flex;
  gap: 24px;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border-radius: 14px;
  padding: 20px 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  border: 1px solid #d1fae5;
}
.portal-card.wecom-card {
  border-color: #bfdbfe;
  background: linear-gradient(135deg, #fff, #f8fbff);
}
.wecom-preview-box {
  width: 220px;
  height: 220px;
  border-radius: 12px;
  background: linear-gradient(160deg, #1e293b, #334155);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 2px;
  line-height: 1.4;
}
.portal-left { flex: 1; min-width: 0; }
.portal-label {
  display: inline-block;
  font-size: 12px;
  color: #0f766e;
  background: #ecfdf5;
  padding: 3px 8px;
  border-radius: 999px;
  margin-bottom: 8px;
  font-weight: 600;
}
.portal-card h2 { margin: 0 0 8px; font-size: 20px; }
.portal-url {
  margin: 12px 0;
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
  background: #f8fafc;
  padding: 8px 10px;
  border-radius: 8px;
}
.portal-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.portal-right {
  flex-shrink: 0;
  padding: 10px;
  background: #f8fafc;
  border-radius: 12px;
  border: 1px solid var(--line);
}
#portal_canvas { display: block; background: #fff; border-radius: 6px; }
#portal_img {
  display: block;
  width: 220px;
  height: 220px;
  object-fit: contain;
  background: #fff;
  border-radius: 6px;
}
.qr-box {
  width: 240px;
  height: 240px;
  margin: 12px auto;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qr-box img { width: 240px; height: 240px; object-fit: contain; }

@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
  }
  .brand { font-size: 14px; }
  .brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: calc(100vw - 80px); }
  .top-actions { width: 100%; }
  .top-actions .btn { flex: 1; }
  .portal-card {
    flex-direction: column-reverse;
    text-align: center;
    padding: 16px;
    gap: 14px;
  }
  .portal-actions { justify-content: center; }
  .portal-actions .btn { width: 100%; }
  .portal-right {
    padding: 8px;
    width: 100%;
    display: flex;
    justify-content: center;
  }
  #portal_img,
  .wecom-preview-box {
    width: 160px;
    height: 160px;
  }
  .wecom-preview-box { font-size: 16px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar input[type=search] { max-width: none; width: 100%; }
  .ops { flex-direction: column; }
  .ops .btn { width: 100%; }
  .table { min-width: 640px; }
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.toolbar input[type=search] {
  flex: 1;
  max-width: 320px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.table-wrap {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
}
.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
}
.table th, .table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}
.table th {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  background: #fafbfc;
}
.table tr:last-child td { border-bottom: 0; }
.table .empty { text-align: center; color: var(--muted); padding: 36px; }

.thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #f9fafb;
}
.no-img {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  border: 1px dashed #cbd5e1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 11px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
}
.badge-on { background: #d1fae5; color: #065f46; }
.badge-off { background: #fee2e2; color: #991b1b; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  line-height: 1.2;
}
.btn:hover { background: #f8fafc; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-sm { padding: 5px 8px; font-size: 12px; }
.btn.block { width: 100%; margin-top: 8px; }

/* auth */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(13,148,136,.18), transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(14,165,233,.12), transparent 45%),
    #0b1220;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 14px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 6px; font-size: 22px; }
.auth-card .sub { color: var(--muted); margin: 0 0 18px; }
.auth-card label { display: block; margin: 12px 0 6px; font-size: 13px; color: var(--muted); }
.auth-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
}
.auth-card .hint { font-size: 13px; color: var(--muted); line-height: 1.6; margin: 12px 0 16px; }
.alert {
  background: #fef2f2;
  color: #b91c1c;
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 10px;
  font-size: 13px;
}

/* modal */
.modal[hidden] { display: none !important; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .45);
}
.modal-panel {
  position: relative;
  width: min(100%, 440px);
  background: #fff;
  border-radius: 14px;
  padding: 22px 20px;
  box-shadow: 0 20px 50px rgba(0,0,0,.2);
  max-height: 90vh;
  overflow: auto;
}
.modal-panel.center { text-align: center; }
.modal-panel h2 { margin: 0 0 12px; font-size: 18px; }
.modal-panel label { display: block; margin: 12px 0 6px; font-size: 13px; color: var(--muted); }
.modal-panel input[type=text] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
  flex-wrap: wrap;
}
.modal-panel.center .modal-actions { justify-content: center; }

.preview {
  min-height: 120px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 12px 0;
  background: #fafafa;
  overflow: hidden;
}
.preview img { max-width: 100%; max-height: 220px; }
.file-btn {
  display: inline-flex;
  padding: 9px 14px;
  background: #f1f5f9;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
#qr_canvas { margin: 12px auto; display: block; background: #fff; border-radius: 8px; }
#qr_url { word-break: break-all; margin: 0 0 8px; }

@media (max-width: 640px) {
  .topbar { padding: 12px; }
  .brand { font-size: 15px; }
}
