:root {
  --ink: #111612;
  --moss: #435d45;
  --paper: #f6f2e8;
  --bone: #fbfaf5;
  --brass: #d1a75b;
  --copper: #b77a4c;
  --muted: #747064;
  --line: rgba(17, 22, 18, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family:
    "PingFang SC",
    "Microsoft YaHei",
    system-ui,
    sans-serif;
}

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

button {
  border: 0;
  border-radius: 8px;
  padding: 11px 14px;
  color: var(--bone);
  background: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.ghost {
  border: 1px solid var(--line);
  color: var(--ink);
  background: transparent;
}

.admin-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 28px;
  padding: 22px;
  color: var(--bone);
  background: var(--ink);
}

.brand,
.site-link {
  color: inherit;
  text-decoration: none;
}

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

.brand span {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--moss);
  font-family: "Songti SC", serif;
}

.sidebar nav {
  display: grid;
  align-content: start;
  gap: 8px;
}

.sidebar nav button {
  justify-content: start;
  text-align: left;
  color: rgba(246, 242, 232, 0.72);
  background: transparent;
}

.sidebar nav button.is-active,
.sidebar nav button:hover {
  color: var(--ink);
  background: var(--brass);
}

.site-link {
  padding: 12px;
  border: 1px solid rgba(246, 242, 232, 0.18);
  border-radius: 8px;
  text-align: center;
}

.workspace {
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bone);
}

.topbar p,
.panel-head p,
.notice p,
.login-card p {
  margin: 0;
  color: var(--muted);
}

.topbar h1,
.panel h2,
.login-card h2 {
  margin: 4px 0 0;
  font-family: "Songti SC", serif;
}

.login-card,
.panel {
  display: none;
  margin-top: 18px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bone);
}

body.needs-login .login-card,
.panel.is-active {
  display: block;
}

body.needs-login .panel,
body.needs-login .topbar,
body.needs-login .sidebar {
  display: none;
}

.login-card form,
.upload-box {
  display: grid;
  grid-template-columns: minmax(160px, 0.4fr) minmax(220px, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
}

.login-brandline,
.login-meta {
  display: flex;
  align-items: center;
}

.login-brandline {
  gap: 12px;
  margin-bottom: 24px;
}

.login-brandline strong {
  display: block;
  font-size: 1rem;
}

.login-brandline p {
  margin-top: 2px;
  font-size: 0.78rem;
}

.login-logo {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--bone);
  background:
    linear-gradient(135deg, rgba(67, 93, 69, 0.96), rgba(17, 22, 18, 0.96)),
    var(--ink);
  font-family: "Songti SC", serif;
  font-size: 1.3rem;
  font-weight: 900;
  box-shadow: 0 14px 32px rgba(17, 22, 18, 0.16);
}

.login-kicker {
  color: var(--copper);
  font-size: 0.8rem;
  font-weight: 900;
}

.login-intro {
  max-width: 420px;
  line-height: 1.7;
}

.login-meta {
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.login-meta span {
  border: 1px solid rgba(183, 122, 76, 0.2);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--copper);
  background: rgba(183, 122, 76, 0.08);
  font-size: 0.78rem;
  font-weight: 900;
}

body.needs-login {
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(17, 22, 18, 0.96), rgba(67, 93, 69, 0.88) 46%, rgba(246, 242, 232, 0.96) 46.2%),
    var(--paper);
}

body.needs-login .admin-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
  padding: 28px;
}

body.needs-login .workspace {
  width: min(100%, 1060px);
  display: grid;
  place-items: center;
  padding: 0;
}

body.needs-login .login-card {
  width: min(100%, 480px);
  margin: 0;
  padding: 34px;
  border: 1px solid rgba(17, 22, 18, 0.12);
  border-radius: 8px;
  background: rgba(251, 250, 245, 0.96);
  box-shadow: 0 28px 80px rgba(17, 22, 18, 0.18);
}

body.needs-login .login-card h2 {
  margin-top: 6px;
  font-size: clamp(2rem, 5vw, 3.2rem);
  line-height: 1.05;
}

body.needs-login .login-card form {
  grid-template-columns: 1fr;
  gap: 14px;
  margin-top: 24px;
}

body.needs-login .login-card input {
  min-height: 48px;
  background: #fffdf7;
}

body.needs-login .login-card button[type="submit"] {
  min-height: 50px;
  margin-top: 4px;
}

body.needs-login [data-login-status] {
  min-height: 24px;
}

.upload-box {
  grid-template-columns: minmax(0, 1fr) auto;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  background: #fffdf7;
}

input[readonly] {
  color: var(--muted);
  background: #f4efe2;
}

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

.form-grid.compact {
  margin-bottom: 16px;
}

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

.field-title,
label span {
  font-size: 0.86rem;
}

.field-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.help-tip {
  position: relative;
  width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(183, 122, 76, 0.32);
  border-radius: 999px;
  color: var(--copper);
  background: rgba(183, 122, 76, 0.08);
  font-size: 0.74rem;
  line-height: 1;
  cursor: help;
}

.help-tip span {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: calc(100% + 8px);
  width: min(280px, 70vw);
  display: none;
  transform: translateX(-50%);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fffdf7;
  box-shadow: 0 18px 46px rgba(17, 22, 18, 0.14);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.55;
}

.help-tip:hover span,
.help-tip:focus span {
  display: block;
}

label small,
.checkbox-field small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.45;
}

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

.stack-list,
.backup-list {
  display: grid;
  gap: 14px;
}

.editor-card {
  display: grid;
  gap: 14px;
}

.editor-card header,
.backup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.editor-card header strong {
  color: var(--copper);
  font-size: 1.1rem;
}

.danger {
  color: #a33b2f;
  border-color: rgba(163, 59, 47, 0.22);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.toolbar,
.lead-tools,
.upload-result {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.lead-tools {
  grid-template-columns: 150px minmax(180px, 1fr) auto auto;
  margin: 6px 0 0;
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 900;
  text-decoration: none;
}

.upload-result {
  grid-template-columns: minmax(0, 1fr) auto auto;
  margin: 16px 0 0;
}

.upload-result code {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fffdf7;
}

.upload-result span {
  color: var(--muted);
  font-size: 0.84rem;
}

.image-field {
  padding: 14px;
  border: 1px solid rgba(17, 22, 18, 0.12);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.78);
}

.image-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.image-tools button {
  min-height: 36px;
}

.image-preview {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 0.82rem;
}

.image-preview img {
  width: 96px;
  height: 64px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.image-preview code {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: var(--bone);
}

.image-preview.is-empty {
  grid-template-columns: 1fr;
  padding: 10px;
  border: 1px dashed rgba(17, 22, 18, 0.18);
  border-radius: 8px;
}

.image-upload-status {
  min-height: 18px;
  font-weight: 800;
}

.backup-row div {
  display: grid;
  gap: 4px;
}

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

.summary-grid,
.health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
}

.summary-grid article,
.health-grid article,
.notice,
.lead-card,
.editor-card,
.backup-row {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
}

.summary-grid span {
  display: block;
  color: var(--copper);
  font-size: 2.3rem;
  font-weight: 900;
}

.notice {
  margin-top: 16px;
}

.health-grid {
  margin-top: 16px;
}

.health-grid article {
  display: grid;
  gap: 4px;
}

.health-grid strong {
  color: var(--moss);
  font-size: 0.8rem;
}

.health-grid .is-warn strong {
  color: #a33b2f;
}

.health-grid span {
  font-weight: 900;
}

.health-grid p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

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

.panel-head h2,
.notice h2,
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title {
  margin: 8px 0 12px;
}

.section-title h3 {
  margin: 0;
  font-family: "Songti SC", serif;
}

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

.json-editor {
  min-height: 62vh;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92rem;
  line-height: 1.55;
  resize: vertical;
}

.status {
  min-height: 24px;
  margin: 12px 0 0;
  color: var(--moss);
  font-weight: 900;
}

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

.lead-card {
  display: grid;
  gap: 8px;
}

.lead-card header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.lead-card strong {
  color: var(--copper);
}

.lead-card p {
  margin: 0;
  color: var(--muted);
}

.lead-details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
  margin: 0;
}

.lead-details div {
  padding: 10px;
  border: 1px solid rgba(17, 22, 18, 0.1);
  border-radius: 8px;
  background: rgba(246, 242, 232, 0.48);
}

.lead-details dt {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
}

.lead-details dd {
  margin: 4px 0 0;
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.45;
  word-break: break-word;
}

.email-form {
  display: grid;
  gap: 16px;
}

.email-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border: 1px solid rgba(183, 122, 76, 0.2);
  border-radius: 8px;
  background: rgba(209, 167, 91, 0.1);
}

.email-banner strong {
  color: var(--copper);
}

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

.checkbox-field {
  min-height: 72px;
  align-content: center;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
}

.checkbox-field input {
  width: auto;
  margin-top: 2px;
}

.checkbox-field small {
  grid-column: 2;
}

.email-test-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 22, 18, 0.03);
}

@media (max-width: 820px) {
  .admin-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
  }

  .summary-grid,
  .health-grid,
  .form-grid,
  .panel-head,
  .toolbar,
  .lead-tools,
  .backup-row,
  .email-banner,
  .email-test-row,
  .login-card form,
  .upload-box {
    grid-template-columns: 1fr;
    display: grid;
  }

  label.wide {
    grid-column: auto;
  }

  .image-preview,
  .upload-result {
    grid-template-columns: 1fr;
  }
}
