:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #e5e9f2;
  --border-strong: #cdd5e0;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #dbeafe;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --success: #16a34a;
  --warn: #f59e0b;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
}

input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
}

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  gap: 16px;
}

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

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #6366f1);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-sm);
}

.brand-title {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
}

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

.me-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  padding: 8px 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.45;
  max-width: 280px;
}
.me-card .me-line { display: contents; }
.me-card .me-k {
  color: var(--text-muted);
  white-space: nowrap;
}
.me-card .me-v {
  color: var(--text);
  font-weight: 500;
  word-break: break-all;
}

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 0% 0%, #dbeafe 0%, transparent 60%),
    radial-gradient(1200px 600px at 100% 100%, #e0e7ff 0%, transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 28px 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-head {
  text-align: center;
  margin-bottom: 4px;
}
.login-logo {
  width: 52px;
  height: 52px;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-title {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 600;
}
.login-sub {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}
.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.login-field > span {
  font-size: 12px;
  color: var(--text-muted);
}
.login-field > input {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.login-field > input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.login-err {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
}
.login-tip {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
}
.login-card .btn-primary {
  width: 100%;
  height: 42px;
  margin-top: 4px;
}

/* ---------- Buttons ---------- */

.btn-primary,
.btn-ghost,
.btn-danger {
  height: 36px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-ghost:hover {
  background: var(--surface-soft);
  border-color: var(--text-muted);
}

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

.btn-danger:hover {
  background: #b91c1c;
  border-color: #b91c1c;
}

.bg-icon {
  display: inline-block;
  font-size: 14px;
}

/* ---------- Page ---------- */

.page {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 24px 48px;
}

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

.page-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 4px;
}

.page-sub {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  max-width: 720px;
}

.dirty-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #fff7ed;
  color: #c2410c;
  border: 1px solid #fdba74;
  font-size: 12px;
  font-weight: 500;
}

.dirty-badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ea580c;
}

/* ---------- Form ---------- */

.form-area {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-soft);
}

.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-pill {
  font-size: 11px;
  font-weight: 500;
  background: var(--primary-soft);
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 999px;
}

.section-desc {
  font-size: 12px;
  color: var(--text-muted);
}

.section-body {
  padding: 8px 20px 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 20px;
}

.section-body.single {
  grid-template-columns: 1fr;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 0;
  border-bottom: 1px dashed var(--border);
}

.field:last-child,
.field.full + .field,
.section-body > .field:nth-last-child(-n + 2) {
  border-bottom: none;
}

.field.full {
  grid-column: 1 / -1;
}

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.field-note {
  font-size: 12px;
  color: var(--text-muted);
}

.field-restore {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: inline-grid;
  place-items: center;
  font-size: 14px;
  line-height: 1;
  transition: all 0.15s ease;
}

.field-restore:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-soft);
}

.field-restore:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.field-input {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.field-input.is-default {
  background: var(--surface-soft);
  color: var(--text-muted);
}

.field-input.is-modified {
  border-color: var(--warn);
  background: #fffbeb;
}

.field-default {
  font-size: 11px;
  color: var(--text-faint);
  font-style: italic;
  padding-left: 2px;
}

.field-default b {
  font-weight: 500;
  color: var(--text-muted);
  font-style: normal;
}

/* ---------- Image field ---------- */

.btn-sm {
  height: 30px;
  padding: 0 12px;
  font-size: 13px;
}

.image-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.image-row.is-modified {
  border-color: var(--warn);
  background: #fffbeb;
  border-style: solid;
}

.image-preview {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-sm);
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.image-preview.is-empty {
  background: repeating-linear-gradient(
    45deg,
    var(--surface),
    var(--surface) 6px,
    var(--surface-soft) 6px,
    var(--surface-soft) 12px
  );
}

.image-empty-tag {
  font-size: 11px;
  color: var(--text-faint);
}

.image-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
}

.image-meta {
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- Page foot ---------- */

.page-foot {
  margin-top: 24px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ---------- Modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
}

/* 修复：HTML hidden 属性必须能压过 display:flex / display:grid，
   否则登录页和编辑器会同时显示。 */
[hidden] { display: none !important; }

.modal[hidden] {
  display: none;
}

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
}

.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  max-width: 420px;
  width: calc(100% - 40px);
  z-index: 1;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  border-radius: 6px;
}

.modal-close:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.modal-title {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
}

.modal-sub {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.55;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 200;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.2s ease;
}

.toast.is-error {
  background: var(--danger);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  .topbar {
    flex-wrap: wrap;
    padding: 12px 16px;
  }

  .topbar-right {
    width: 100%;
    flex-wrap: wrap;
  }

  .skin-select {
    flex: 1;
  }

  .page {
    padding: 16px 16px 48px;
  }

  .section-body {
    grid-template-columns: 1fr;
    padding: 8px 16px 16px;
  }

  .page-head {
    flex-direction: column;
  }
}
