:root {
  --bg: #eef1f5;
  --bg-deep: #e4e9f0;
  --ink: #12161c;
  --text: #1c232d;
  --muted: #6b7380;
  --line: rgba(18, 28, 42, 0.1);
  --panel: rgba(255, 255, 255, 0.92);
  --panel-solid: #fff;
  --amber: #c4841d;
  --amber-bright: #e8a317;
  --amber-soft: rgba(196, 132, 29, 0.12);
  --amber-line: rgba(196, 132, 29, 0.35);
  --ok: #1a7f37;
  --ok-bg: #eaf7ef;
  --danger: #c62828;
  --danger-bg: #fef2f1;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 12px 36px rgba(18, 28, 42, 0.08);
  --font-display: "Chakra Petch", "Noto Sans SC", sans-serif;
  --font-body: "Noto Sans SC", sans-serif;
  --shell-max: 1180px;
  --aside-w: 360px;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(90% 55% at 8% -5%, rgba(232, 163, 23, 0.14), transparent 55%),
    radial-gradient(70% 50% at 100% 0%, rgba(70, 110, 160, 0.1), transparent 50%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image:
    linear-gradient(rgba(18, 28, 42, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(18, 28, 42, 0.03) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at 50% 20%, black 20%, transparent 75%);
}

.shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* —— Top bar —— */
.topbar {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 28px;
  height: 60px;
  background: rgba(255, 255, 255, 0.78);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  animation: rise 0.55s ease both;
}

.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  letter-spacing: 0.06em;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.brand span {
  background: linear-gradient(120deg, var(--ink) 20%, var(--amber) 85%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.nav {
  display: flex;
  gap: 4px;
  flex: 1;
}

.nav a {
  font-size: 0.92rem;
  color: var(--muted);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 999px;
  transition: color 0.15s, background 0.15s;
}

.nav a:hover { color: var(--ink); background: rgba(18, 28, 42, 0.05); }
.nav a.is-active {
  color: var(--ink);
  background: var(--amber-soft);
  font-weight: 600;
}

.top-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
}

.top-meta a {
  color: var(--amber);
  text-decoration: none;
  font-weight: 500;
}
.top-meta a:hover { color: var(--amber-bright); }

.channel-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  font-family: var(--font-display);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: var(--text);
}

/* —— Page frame —— */
.page {
  width: min(var(--shell-max), calc(100% - 48px));
  margin: 0 auto;
  padding: 28px 0 20px;
  flex: 1;
  animation: rise 0.65s ease 0.06s both;
}

.page-login {
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(420px, calc(100% - 48px));
  padding-top: 0;
  padding-bottom: 40px;
}

.footer {
  width: min(var(--shell-max), calc(100% - 48px));
  margin: 0 auto 20px;
  padding-top: 8px;
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  gap: 16px;
  animation: rise 0.7s ease 0.12s both;
}

.footer a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px dashed transparent;
}
.footer a:hover {
  color: var(--amber);
  border-bottom-color: var(--amber-line);
}

/* —— Panels —— */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.panel h2,
.panel-title {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
}

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

.panel-head h2 { margin: 0; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.panel-muted {
  background: rgba(255, 255, 255, 0.55);
  box-shadow: none;
}

.panel-muted .panel-title,
.panel-muted h2 {
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 500;
}

.help-tip {
  margin: 0 0 14px;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.55;
}

.muted { color: var(--muted); font-size: 0.88rem; }

/* —— Workspace layouts —— */
.workspace {
  display: grid;
  grid-template-columns: var(--aside-w) 1fr;
  gap: 20px;
  align-items: start;
}

.workspace-aside {
  position: sticky;
  top: 76px;
}

.workspace-main {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

.stack { display: flex; flex-direction: column; gap: 20px; }

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

.page-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 650;
  letter-spacing: 0.03em;
  color: var(--ink);
}

.mt-section { margin-top: 20px; }

/* —— Forms —— */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
}

.form-grid .span-2,
.form-grid .member-field,
.form-grid .check-inline.span-2 { grid-column: 1 / -1; }

label, .field {
  display: block;
  margin-bottom: 0;
  font-size: 0.84rem;
  color: var(--text);
}

.field-label,
label > .lbl,
.lbl {
  display: block;
  margin-bottom: 6px;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.06em;
}

.req { color: var(--danger); font-size: 0.75rem; }

input,
select,
textarea {
  display: block;
  width: 100%;
  margin-top: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  font-size: 0.92rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

/* 全局 textarea{display:block} 会盖掉 [hidden]，提交用字段必须强制隐藏 */
textarea[hidden],
input[type="hidden"],
.member-refs-store {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-soft);
}

.actions { margin-top: 14px; }
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}
.btn-row form { margin: 0; }

button,
a.btn-secondary,
a.btn-primary,
.btn-secondary,
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: #fff;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  font-family: var(--font-body);
  line-height: 1.2;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.12s ease, filter 0.12s ease, background 0.15s;
}

button:hover,
.btn-secondary:hover,
a.btn-secondary:hover { filter: brightness(0.98); }
button:active { transform: scale(0.98); }

.btn-primary,
a.btn-primary,
#confirm-ok {
  background: linear-gradient(135deg, #f0c14d, var(--amber-bright) 45%, var(--amber));
  border-color: transparent;
  color: #1a1204;
  font-weight: 650;
  font-family: var(--font-display);
  letter-spacing: 0.04em;
}

.btn-primary:hover,
a.btn-primary:hover { filter: brightness(1.04); }

.btn-sm {
  padding: 7px 12px;
  font-size: 0.84rem;
}

.btn-danger {
  color: var(--danger);
  border-color: #f0b8b4;
  background: #fff;
}
.btn-danger:hover { background: var(--danger-bg); }

button:disabled,
button.is-busy {
  opacity: 0.5;
  cursor: not-allowed;
  filter: none;
  transform: none;
  pointer-events: none;
}

.link-btn {
  border: 0;
  background: none;
  padding: 0;
  color: var(--amber);
  cursor: pointer;
  font-size: inherit;
  font-family: inherit;
}
.link-btn.danger { color: var(--danger); }
.link-btn:hover { text-decoration: underline; }

.check-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
  font-size: 0.88rem;
}
.check-inline input { width: auto; margin: 0; }

/* —— Tables —— */
.table-wrap { overflow: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

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

th {
  font-size: 0.75rem;
  text-transform: none;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 500;
}

tbody tr { transition: background 0.12s; }
tbody tr:hover { background: rgba(196, 132, 29, 0.05); }
tbody tr.is-editing > td {
  background: rgba(196, 132, 29, 0.06);
}

.cell-strong {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  white-space: nowrap;
}

.row-actions a {
  color: var(--amber);
  text-decoration: none;
  font-weight: 500;
}
.row-actions a:hover { text-decoration: underline; }

.inline-form { display: inline; margin: 0; }

.row-expand > td {
  padding: 0 10px 16px;
  background: rgba(255, 255, 255, 0.55);
  vertical-align: top;
}

.panel-inset {
  margin-top: 4px;
  padding: 16px 14px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-solid);
}

.table-compact th,
.table-compact td {
  padding: 8px 8px;
  font-size: 0.84rem;
}

/* —— Status pills —— */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.pill-ok {
  background: var(--ok-bg);
  color: var(--ok);
}
.pill-wait {
  background: var(--amber-soft);
  color: #8a5a10;
}

/* —— Alerts —— */
.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.9rem;
  border: 1px solid transparent;
  animation: rise 0.4s ease both;
}
.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: rgba(198, 40, 40, 0.18);
}
.alert-ok {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: rgba(26, 127, 55, 0.18);
}

/* —— Dialog —— */
dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  max-width: 420px;
  box-shadow: 0 24px 60px rgba(18, 28, 42, 0.18);
  background: #fff;
}
dialog::backdrop { background: rgba(18, 28, 42, 0.35); backdrop-filter: blur(2px); }
dialog[open] { animation: pop 0.28s cubic-bezier(0.2, 0.9, 0.2, 1); }
dialog p { margin: 0 0 16px; line-height: 1.5; }
dialog menu {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 0;
  margin: 0;
}

/* —— Meta / QR —— */
.meta-list {
  margin: 0;
  display: grid;
  gap: 10px;
}

.meta-list > div {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 8px;
  font-size: 0.9rem;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--line);
}
.meta-list > div:last-child { border-bottom: 0; padding-bottom: 0; }

.meta-list dt {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}
.meta-list dd {
  margin: 0;
  font-weight: 500;
  word-break: break-all;
}

.qr-panel {
  text-align: center;
}

.qr-frame {
  margin: 12px auto 16px;
  width: min(260px, 100%);
  aspect-ratio: 1;
  padding: 14px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid var(--amber-line);
  box-shadow: 0 16px 40px rgba(18, 28, 42, 0.1);
}

.qr-img,
.qr-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.qr-wrap {
  margin: 12px 0;
  text-align: center;
}
.qr-wrap .qr-img {
  max-width: 280px;
  width: 100%;
  height: auto;
  border: 1px solid var(--amber-line);
  border-radius: 12px;
  background: #fff;
  padding: 10px;
}

.member-field {
  position: relative;
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.member-field > .lbl { margin-bottom: 0; }
.member-field > input[type="text"],
.member-field > input[type="search"] { margin: 0; }

.member-tag-tray {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.72);
}
.member-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.member-empty {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}
.member-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 5px 8px 5px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  box-shadow: 0 1px 0 rgba(18, 28, 42, 0.03);
  line-height: 1.2;
  animation: rise 0.25s ease both;
}
.member-tag-name {
  font-family: var(--font-display);
  font-size: 0.86rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
}
.member-tag-id {
  color: var(--muted);
  font-size: 0.72rem;
  font-family: var(--font-body);
  max-width: 10em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(18, 28, 42, 0.04);
}
.member-tag-x {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.05rem;
  line-height: 1;
  padding: 0 2px;
  border-radius: 4px;
}
.member-tag-x:hover {
  color: var(--danger);
  background: var(--danger-bg);
}

.member-chips-compact {
  gap: 6px;
}
.member-tag-sm {
  padding: 3px 8px;
  gap: 0;
  box-shadow: none;
  animation: none;
}
.member-tag-sm .member-tag-name {
  font-size: 0.78rem;
  font-weight: 500;
}

.ac-box {
  position: relative;
  z-index: 5;
  margin-top: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.1);
  max-height: 220px;
  overflow: auto;
}

.ac-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
  padding: 10px 12px;
  font-size: 0.84rem;
  cursor: pointer;
}
.ac-item:last-child { border-bottom: 0; }
.ac-item:hover { background: var(--amber-soft); }
.ac-item-disabled,
.ac-item-disabled:hover {
  color: var(--muted);
  cursor: not-allowed;
  background: #fafafa;
}

/* —— Login —— */
.login-card {
  width: 100%;
  padding: 32px 28px 28px;
  text-align: left;
}

.login-brand {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: linear-gradient(120deg, var(--ink) 15%, var(--amber) 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.login-card .field { margin-bottom: 14px; }
.login-card .actions { margin-top: 18px; }
.login-card .btn-primary { width: 100%; padding: 12px; }

.empty {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pop {
  from { opacity: 0; transform: scale(0.96) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .workspace-aside { position: static; }
  .detail-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .panel-head {
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 12px 16px;
    gap: 10px;
  }
  .page {
    width: calc(100% - 32px);
    padding-top: 20px;
  }
}
