:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1a1d26;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-pressed: #1d4ed8;
  --ok: #059669;
  --border: #e5e7eb;
  --warn: #d97706;
  --radius: 14px;
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.wrap {
  max-width: 460px;
  margin: 0 auto;
  padding: 24px 16px 88px;
}

header.appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 16px;
}

header.appbar h1 {
  font-size: 1.18rem;
  margin: 0;
  font-weight: 700;
}

.back {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.card h2 {
  font-size: 1.1rem;
  margin: 0 0 6px;
}

.card-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.step-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--primary);
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  padding: 3px 10px;
  border-radius: 999px;
}

.link-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--primary);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 4px 6px;
  min-height: 32px;
  cursor: pointer;
  border-radius: 6px;
}

.link-btn:hover {
  background: #eff6ff;
}

.muted {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 4px 0 14px;
}

label {
  display: block;
  font-size: 0.86rem;
  margin-bottom: 5px;
  color: #374151;
  font-weight: 600;
}

input[type="email"],
input[type="text"],
textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 0.96rem;
  margin-bottom: 14px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="email"]:focus,
input[type="text"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.code-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.35rem !important;
  letter-spacing: 0.3em;
  text-align: center;
  font-weight: 700;
}

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

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.row > button {
  flex: 1;
}

button,
.btn {
  appearance: none;
  border: none;
  background: var(--primary);
  color: #fff;
  padding: 10px 16px;
  border-radius: 9px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
}

button:active,
.btn:active {
  background: var(--primary-pressed);
}

button.secondary,
.btn.secondary {
  background: #fff;
  color: var(--primary);
  border: 1px solid var(--primary);
}

button:disabled,
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.block {
  width: 100%;
}

.tabs {
  display: flex;
  gap: 6px;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 16px;
}

.tab-btn {
  flex: 1;
  min-height: 38px;
  padding: 6px 12px;
  border-radius: 8px;
  background: transparent;
  color: #475569;
  font-size: 0.92rem;
  font-weight: 600;
}

.tab-btn.active {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.role-portal {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin: 12px 0 4px;
}

.portal-card {
  display: block;
  padding: 16px 18px;
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}

.portal-card:hover {
  border-color: var(--primary);
  background: #eff6ff;
}

.portal-card .portal-title {
  font-size: 1.06rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}

.portal-card .portal-desc {
  font-size: 0.86rem;
  color: var(--muted);
}

.card-foot-note {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #f1f5f9;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

.card-foot-note a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

.code-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.25rem;
  letter-spacing: 0.08em;
  background: #f0f4ff;
  border: 1px dashed #93c5fd;
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  word-break: break-all;
  margin: 8px 0 12px;
}

.code-box.big {
  font-size: 1.75rem;
  letter-spacing: 0.35em;
  font-weight: 700;
  color: var(--primary);
}

.pill {
  display: inline-block;
  font-size: 0.78rem;
  padding: 3px 10px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  font-weight: 600;
}

.pill.ok {
  background: #d1fae5;
  color: #065f46;
}

.pill.pending {
  background: #fef3c7;
  color: #92400e;
}

.pill.muted {
  background: #f3f4f6;
  color: #4b5563;
}

.workspace-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.btn-compact {
  min-height: 34px;
  padding: 6px 12px;
  font-size: 0.84rem;
}

.list-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  background: #fff;
}

.list-item:hover,
.list-item.selected {
  border-color: var(--primary);
  background: #f8faff;
}

.list-item .stem {
  font-size: 0.95rem;
  margin: 4px 0 0;
}

.validity {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 8px;
  margin: 10px 0 14px;
}

.validity label.opt {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 0;
  cursor: pointer;
  color: var(--text);
  font-size: 0.95rem;
  min-height: 44px;
}

.validity label.opt:has(input:checked) {
  border-color: var(--primary);
  background: #eff6ff;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 100;
  max-width: 90%;
}

.toast.show {
  opacity: 1;
}

.success-banner {
  display: none;
  background: #ecfdf5;
  border: 1.5px solid #10b981;
  color: #065f46;
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 12px;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.5;
}

.success-banner.show {
  display: block;
}

.err {
  color: #b91c1c;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.86rem;
  margin: 8px 0 0;
}

.email-badge {
  display: inline-block;
  background: #eff6ff;
  color: #1d4ed8;
  padding: 2px 8px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 600;
  text-decoration: none;
}

/* Bottom-right floating action button for "发送管理员" popup card */
.fab-support {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 40;
  background: #ffffff;
  color: var(--primary);
  border: 1.5px solid #bfdbfe;
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.16);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 0.88rem;
  font-weight: 600;
  min-height: 42px;
  gap: 6px;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.fab-support:hover {
  border-color: var(--primary);
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.24);
  transform: translateY(-1px);
}

.fab-support:active {
  background: #eff6ff;
}

/* Native <dialog> modal for "发送管理员" card */
dialog.support-dialog {
  width: calc(100% - 32px);
  max-width: 440px;
  border: none;
  border-radius: 16px;
  padding: 0;
  background: transparent;
  box-shadow: 0 20px 44px rgba(15, 23, 42, 0.24);
}

dialog.support-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

dialog.support-dialog .support-card {
  margin: 0;
  border-top: 4px solid var(--primary);
  border-radius: 16px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.dialog-head h2 {
  margin: 0;
}

.dialog-close-btn {
  appearance: none;
  background: #f1f5f9;
  color: #475569;
  border: none;
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 999px;
  font-size: 0.95rem;
  cursor: pointer;
}

.dialog-close-btn:hover {
  background: #e2e8f0;
  color: #0f172a;
}

/* Binding & QR Code & Dialog Context Preview Styles */
.bind-status-box {
  background: #f0fdf4;
  border: 1.5px solid #86efac;
  border-radius: 10px;
  padding: 12px 14px;
  margin: 10px 0 14px;
  font-size: 0.9rem;
  color: #065f46;
}

.bind-status-box.unbound {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

.qr-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  padding: 14px;
  margin: 10px 0 14px;
  text-align: center;
}

.qr-scan-hint {
  margin: 0 0 10px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #1e3a8a;
  line-height: 1.5;
}

/* Quiet zone and the white card live on the wrapper.
   Padding, border, or border-radius on the svg itself clips a symbol
   that has width/height but no viewBox (the right and bottom modules disappear). */
.qr-svg-box {
  width: min(248px, 100%);
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 16px;
}

.qr-svg-box svg {
  width: 100%;
  height: auto;
  display: block;
  background: #fff;
  overflow: visible;
}

.invite-url-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  background: #f1f5f9;
  color: #334155;
  padding: 8px 10px;
  border-radius: 8px;
  word-break: break-all;
  margin: 6px 0 10px;
  border: 1px solid #e2e8f0;
}

.section-divider {
  border: none;
  border-top: 1px solid #e5e7eb;
  margin: 16px 0;
}

.dialog-thread {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px;
  margin: 10px 0 14px;
  max-height: 320px;
  overflow-y: auto;
}

.dialog-msg {
  padding: 8px 11px;
  border-radius: 9px;
  margin-bottom: 8px;
  font-size: 0.88rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.dialog-msg:last-child {
  margin-bottom: 0;
}

.dialog-msg.student {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e3a8a;
}

.dialog-msg.ai {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  color: #1e293b;
}

.dialog-role {
  font-size: 0.76rem;
  font-weight: 700;
  margin-bottom: 3px;
  opacity: 0.85;
}

.bound-student-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  margin-bottom: 8px;
  background: #f8fafc;
  font-size: 0.88rem;
}

.fallback-code-box {
  background: #f8fafc;
  border: 1.5px dashed #cbd5e1;
  border-radius: 12px;
  padding: 12px 14px 6px;
  margin: 10px 0 6px;
}

.fallback-code-title {
  font-size: 0.86rem;
  color: #334155;
  font-weight: 600;
  line-height: 1.45;
  margin-bottom: 6px;
}

.shot-card { margin: 8px 0 4px; }
.shot-thumb {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  user-select: none;
}
.shot-thumb img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  pointer-events: none;
}
.shot-hint {
  margin: 6px 0 0;
  font-size: 0.78rem;
  color: #64748b;
  line-height: 1.4;
}
.shot-viewer {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: #0f172a;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
}
.shot-viewer[hidden],
.shot-sheet[hidden] { display: none !important; }
.shot-viewer-bar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 10px 12px;
  background: #111827;
  color: #f8fafc;
}
.shot-viewer-bar span {
  grid-column: 1 / -1;
  min-width: 0;
  font-size: 0.95rem;
}
@media (max-width: 520px) {
  .shot-viewer-bar { grid-template-columns: 1fr; }
}
.shot-viewer-bar button,
.shot-sheet-card button {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 0 8px;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #0f172a;
  font-size: 0.95rem;
}
.shot-viewer-bar button {
  background: #1e293b;
  color: #f8fafc;
  border-color: #334155;
}
#shotViewMax, #shotSave, #shotSheetMax, #shotSheetSave {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}
.shot-stage {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
}
.shot-stage img.fit {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  margin: 0 auto;
}
.shot-stage img.max {
  display: block;
  max-width: none;
  max-height: none;
  margin: 0;
}
.shot-sheet {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.shot-sheet-card {
  width: min(460px, 100%);
  background: #fff;
  border-radius: 16px 16px 0 0;
  padding: 12px 12px 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.shot-sheet-card button { width: 100%; }


