:root {
  --bg: #f3f6fb;
  --bg-deep: #e9eff8;
  --card: #ffffff;
  --ink: #172033;
  --muted: #68748a;
  --line: #e3e9f2;
  --blue: #2f6fed;
  --blue-dark: #1f56c9;
  --blue-soft: #edf3ff;
  --green: #1e9e6a;
  --green-soft: #e9f8f1;
  --amber: #b7791f;
  --amber-soft: #fff7e5;
  --red: #d64545;
  --red-soft: #fff0f0;
  --shadow: 0 16px 48px rgba(28, 48, 86, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 12% -10%, #e5efff 0%, transparent 55%),
    radial-gradient(900px 500px at 95% 0%, #eef8f3 0%, transparent 48%),
    linear-gradient(180deg, var(--bg) 0%, #f8fafc 100%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

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

button { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid rgba(227, 233, 242, 0.92);
  backdrop-filter: blur(16px);
}

.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(135deg, #3b7cff, #1852c7);
  box-shadow: 0 6px 14px rgba(47, 111, 237, 0.28);
  font-size: 15px;
}

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

.page {
  width: min(100% - 28px, 780px);
  margin: 0 auto;
  padding: 24px 0 56px;
}

.page.wide { width: min(100% - 28px, 1120px); }

.hero {
  padding: 22px 4px 18px;
}

.hero h1 {
  margin: 0 0 6px;
  font-size: clamp(24px, 4.2vw, 34px);
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.hero p {
  margin: 0;
  color: var(--muted);
  max-width: 680px;
}

.card {
  background: var(--card);
  border: 1px solid rgba(227, 233, 242, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-pad { padding: 24px; }

.card + .card { margin-top: 18px; }

.section-title {
  margin: 0 0 4px;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.section-subtitle {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 18px;
}

.field { min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field.half { grid-column: span 1; }

.field-label {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 7px;
  font-weight: 600;
  font-size: 14px;
}

.required { color: var(--red); font-weight: 700; }

.field-help {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}

.field-error {
  margin: 6px 0 0;
  color: var(--red);
  font-size: 12.5px;
  min-height: 0;
}

.token-input { -webkit-text-security: disc; }

.input, .textarea, .select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fbfcff;
  border-radius: 12px;
  padding: 12px 13px;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.input:focus, .textarea:focus, .select:focus {
  border-color: #9dbafb;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(47, 111, 237, 0.1);
}

.textarea { min-height: 106px; resize: vertical; }

.input[aria-invalid="true"], .textarea[aria-invalid="true"] {
  border-color: #f0a6a6;
  background: #fffafa;
}

.radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.radio-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fbfcff;
  color: #354159;
  transition: all 0.16s ease;
}

.radio-pill:hover { border-color: #b8c9ee; }

.radio-pill input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.radio-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c4cfdf;
  box-shadow: 0 0 0 4px transparent;
}

.radio-pill:has(input:checked) {
  color: var(--blue-dark);
  border-color: #a9c1fb;
  background: var(--blue-soft);
  font-weight: 600;
}

.radio-pill:has(input:checked) .radio-dot {
  background: var(--blue);
  box-shadow: 0 0 0 4px rgba(47, 111, 237, 0.12);
}

.picker {
  width: 100%;
  min-height: 48px;
  border: 1px dashed #cbd8ea;
  background: #fbfcff;
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  transition: all 0.16s ease;
}

.picker:hover {
  border-color: #9dbafb;
  background: #f8fbff;
}

.picker-placeholder { color: #8a96aa; }

.picker-value {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: #234cae;
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.chip [data-remove-user] {
  border: 0;
  background: transparent;
  color: #5576bd;
  padding: 0;
  line-height: 1;
  font-size: 16px;
  cursor: pointer;
}

.picker-action {
  flex: 0 0 auto;
  font-size: 13px;
  color: var(--blue);
  font-weight: 600;
}

.form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.form-note { color: var(--muted); font-size: 12.5px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
  background: #f3f6fb;
  color: #354159;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:hover { filter: brightness(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, #3c7cff, #255ed6);
  box-shadow: 0 8px 18px rgba(47, 111, 237, 0.22);
}

.btn-primary:hover { box-shadow: 0 10px 22px rgba(47, 111, 237, 0.3); }

.btn-ghost { background: #fff; border-color: var(--line); }
.btn-danger { color: var(--red); background: var(--red-soft); }
.btn-small { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

.notice {
  border: 1px solid #cadbfa;
  background: #f4f8ff;
  color: #315a9f;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13.5px;
  line-height: 1.6;
}

.notice.warn {
  border-color: #f1dfb1;
  background: var(--amber-soft);
  color: #825a16;
}

.notice.error {
  border-color: #f0c4c4;
  background: var(--red-soft);
  color: #a53030;
}

.success-panel {
  padding: 32px 22px;
  text-align: center;
}

.success-icon {
  width: 62px;
  height: 62px;
  margin: 0 auto 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--green-soft);
  color: var(--green);
  font-size: 30px;
  font-weight: 700;
}

.success-panel h2 {
  margin: 0 0 8px;
  font-size: 24px;
}

.success-panel p { margin: 0 auto 8px; color: var(--muted); max-width: 460px; }

.submission-no {
  display: inline-block;
  margin: 12px 0 20px;
  padding: 7px 12px;
  border-radius: 8px;
  background: #f2f6fc;
  color: #405170;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(18, 30, 52, 0.44);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 18px;
}

.modal {
  width: min(100%, 620px);
  max-height: min(78vh, 700px);
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 30px 80px rgba(12, 26, 54, 0.28);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-title { margin: 0; font-size: 17px; }
.modal-body { padding: 14px 18px; overflow: auto; }
.modal-footer { padding: 12px 18px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

.group-list { display: grid; gap: 8px; }

.group-item {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 11px 12px;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.group-item:hover { border-color: #b4c9f7; background: #f9fbff; }
.group-name { font-weight: 600; font-size: 14px; }
.group-meta { color: var(--muted); font-size: 12px; }

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #d8e3f8;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

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

/* ---------- 首页 ---------- */
.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.form-card {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 170px;
}

.form-card h3 { margin: 0; font-size: 18px; }
.form-card p { margin: 0; color: var(--muted); font-size: 13.5px; flex: 1; }
.form-card .meta { color: #8894a8; font-size: 12px; }

/* ---------- 管理端 ---------- */
.admin-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.admin-sidebar { position: sticky; top: 82px; }

.admin-list { display: grid; gap: 10px; }

.admin-template-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fbfcff;
  cursor: pointer;
  transition: all 0.15s ease;
}

.admin-template-item:hover { border-color: #b8ccf7; background: #f8fbff; }
.admin-template-item.active { border-color: #a9c1fb; background: var(--blue-soft); }

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

.admin-template-name { font-weight: 650; }
.admin-template-desc { color: var(--muted); font-size: 12.5px; margin-top: 3px; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c4cfdf;
  flex: 0 0 auto;
}
.status-dot.on { background: var(--green); box-shadow: 0 0 0 4px rgba(30, 158, 106, 0.1); }

.admin-main { min-width: 0; }

.editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.editor-title { margin: 0; font-size: 20px; }

.editor-actions { display: flex; gap: 9px; flex-wrap: wrap; }

.field-editor-list { display: grid; gap: 12px; }

.field-editor {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fbfcff;
}

.field-editor-top {
  display: grid;
  grid-template-columns: 1.1fr 1fr 140px;
  gap: 10px;
  align-items: end;
}

.field-editor-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.checkline {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #4e5b70;
  font-size: 13px;
}

.checkline input { width: 15px; height: 15px; accent-color: var(--blue); }

.options-input { min-height: 72px; }

.field-editor-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 10px;
}

.condition-row {
  display: grid;
  grid-template-columns: 1fr 130px 1fr;
  gap: 8px;
  margin-top: 10px;
  padding: 10px;
  border-radius: 10px;
  background: #f3f6fb;
}

.condition-label { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }

.mini-label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }

.mini-input, .mini-select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 7px 9px;
  font-size: 13px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.stat {
  padding: 13px 14px;
  border-radius: 12px;
  background: #f7f9fd;
  border: 1px solid #edf1f7;
}
.stat-label { color: var(--muted); font-size: 12px; }
.stat-value { font-size: 23px; font-weight: 700; line-height: 1.3; }

.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th, .table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.table th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
.table td { color: #344058; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.green { background: var(--green-soft); color: #157b53; }
.badge.amber { background: var(--amber-soft); color: #8a5c12; }
.badge.red { background: var(--red-soft); color: #a53030; }
.badge.gray { background: #f1f4f9; color: #67748b; }

.footer-note {
  color: #8a96aa;
  text-align: center;
  font-size: 12px;
  padding-top: 22px;
}

@media (max-width: 860px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-sidebar { position: static; }
  .status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .page { width: min(100% - 20px, 780px); padding-top: 14px; }
  .card-pad { padding: 18px 16px; }
  .form-grid { grid-template-columns: 1fr; gap: 15px; }
  .field.half { grid-column: 1 / -1; }
  .form-footer { flex-direction: column; align-items: stretch; }
  .form-footer .btn { width: 100%; }
  .field-editor-top { grid-template-columns: 1fr; }
  .condition-row { grid-template-columns: 1fr; }
  .topbar-inner { padding: 10px 14px; }
  .brand span:last-child { font-size: 14px; }
  .modal-mask { padding: 0; align-items: flex-end; }
  .modal { border-radius: 18px 18px 0 0; max-height: 86vh; }
  .hero { padding-top: 16px; }
  .hero h1 { font-size: 25px; }
}
