:root {
  --admin-accent: #5252ad;
  --admin-accent-dark: #41418f;
  --admin-bg: #f5f6f8;
  --admin-surface: #ffffff;
  --admin-text: #20232a;
  --admin-muted: #737782;
  --admin-border: #e2e4e9;
  --admin-danger: #b94242;
  --admin-sidebar: 216px;
  --admin-preview: 340px;
}

* { box-sizing: border-box; }

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

body.admin-body {
  margin: 0;
  color: var(--admin-text);
  background: var(--admin-bg);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button, input, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.admin-topbar {
  position: fixed;
  z-index: 50;
  inset: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 68px;
  padding: 0 22px;
  border-top: 3px solid var(--admin-accent);
  border-bottom: 1px solid var(--admin-border);
  background: rgba(255, 255, 255, 0.97);
}

.admin-brand {
  display: flex;
  align-items: center;
  gap: 15px;
  color: var(--admin-text);
  text-decoration: none;
}

.admin-brand img { width: 170px; height: auto; }
.admin-brand > span { padding-left: 15px; border-left: 1px solid var(--admin-border); }
.admin-brand strong, .admin-brand small { display: block; }
.admin-brand strong { font-size: 14px; font-weight: 600; }
.admin-brand small { margin-top: 3px; color: #9a9da5; font-size: 10px; text-transform: uppercase; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }
.save-status { margin-right: 6px; color: var(--admin-muted); font-size: 12px; white-space: nowrap; }
.save-status i { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: #45a36b; }
.save-status.is-dirty i { background: #d49a32; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  gap: 7px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: 4px;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary { color: #fff; border-color: var(--admin-accent); background: var(--admin-accent); }
.btn-primary:hover { background: var(--admin-accent-dark); }
.btn-quiet { color: #4f535c; border-color: var(--admin-border); background: #fff; }
.btn-quiet:hover { color: var(--admin-accent); border-color: #bdbdd8; }
.btn-danger { color: var(--admin-danger); border-color: #e9caca; background: #fff; }
.btn-danger:hover { background: #fff6f6; }

.admin-shell {
  display: grid;
  grid-template-columns: var(--admin-sidebar) minmax(480px, 1fr) var(--admin-preview);
  min-height: 100vh;
  padding-top: 68px;
}

.admin-sidebar {
  position: fixed;
  z-index: 30;
  left: 0;
  top: 68px;
  bottom: 0;
  width: var(--admin-sidebar);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px 12px;
  border-right: 1px solid var(--admin-border);
  background: #fff;
}

.admin-sidebar nav { display: grid; gap: 4px; }
.nav-item {
  position: relative;
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 4px;
  color: #555a64;
  background: transparent;
  text-align: left;
}

.nav-item .glyphicon { color: #9599a3; font-size: 14px; }
.nav-item b { min-width: 21px; padding: 2px 5px; border-radius: 10px; color: #8b8f97; background: #f0f1f4; font-size: 10px; font-weight: 500; text-align: center; }
.nav-item:hover { background: #f5f5f9; }
.nav-item.is-active { color: var(--admin-accent); background: #eeeeF7; font-weight: 600; }
.nav-item.is-active::before { position: absolute; content: ""; left: 0; width: 3px; height: 22px; background: var(--admin-accent); }
.nav-item.is-active .glyphicon { color: var(--admin-accent); }

.sidebar-tools { display: grid; gap: 3px; padding-top: 14px; border-top: 1px solid var(--admin-border); }
.sidebar-tools button,
.sidebar-upload { display: flex; align-items: center; min-height: 35px; padding: 0 10px; border: 0; color: #696d76; background: transparent; text-align: left; cursor: pointer; }
.sidebar-tools button:hover,
.sidebar-upload:hover { color: var(--admin-accent); background: #f7f7f9; }
.sidebar-tools .glyphicon { width: 25px; }
.sidebar-tools button.danger-link:hover { color: var(--admin-danger); }
.sidebar-upload { position: relative; overflow: hidden; }
.sidebar-upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.admin-main { grid-column: 2; min-width: 0; padding: 34px 38px 70px; }
.editor-heading { display: flex; align-items: flex-end; justify-content: space-between; max-width: 850px; margin: 0 auto 25px; }
.editor-heading p { margin: 0 0 7px; color: var(--admin-accent); font-size: 11px; text-transform: uppercase; }
.editor-heading h1 { margin: 0; font-size: 25px; font-weight: 600; }
.mobile-preview { display: none; }
.editor { max-width: 850px; margin: 0 auto; }

.panel-intro {
  display: flex;
  gap: 12px;
  margin: 0 0 28px;
  padding: 14px 16px;
  border-left: 3px solid var(--admin-accent);
  color: #60646d;
  background: #eeeeF7;
  line-height: 1.7;
}

.panel-intro .glyphicon { margin-top: 4px; color: var(--admin-accent); }
.form-section { margin-bottom: 34px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; min-height: 35px; margin-bottom: 14px; border-bottom: 1px solid var(--admin-border); }
.section-heading h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.section-heading .btn { min-height: 32px; margin-bottom: 8px; padding: 0 11px; font-size: 12px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 20px; }
.field { display: grid; gap: 8px; min-width: 0; }
.field.is-full { grid-column: 1 / -1; }
.field label, .field-label { color: #4b4f57; font-size: 12px; font-weight: 600; }
.field small { color: #92969f; font-size: 11px; line-height: 1.5; }
.text-input, .textarea-input {
  width: 100%;
  border: 1px solid #d8dae0;
  border-radius: 4px;
  outline: none;
  color: #2e3239;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.text-input { height: 40px; padding: 0 11px; }
.textarea-input { min-height: 116px; padding: 10px 11px; line-height: 1.7; resize: vertical; }
.text-input:focus, .textarea-input:focus { border-color: var(--admin-accent); box-shadow: 0 0 0 3px rgba(82, 82, 173, 0.1); }
.color-row { display: grid; grid-template-columns: 46px 1fr; gap: 8px; }
.color-input { width: 46px; height: 40px; padding: 4px; border: 1px solid #d8dae0; border-radius: 4px; background: #fff; }

.visibility-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; min-height: 43px; padding: 0 12px; border: 1px solid var(--admin-border); border-radius: 4px; background: #fff; }
.switch { position: relative; width: 36px; height: 20px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { display: block; width: 100%; height: 100%; border-radius: 10px; background: #c7c9cf; transition: background 0.18s; }
.switch span::after { position: absolute; content: ""; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform 0.18s; }
.switch input:checked + span { background: var(--admin-accent); }
.switch input:checked + span::after { transform: translateX(16px); }

.item-list { display: grid; gap: 12px; }
.edit-item { border: 1px solid var(--admin-border); border-radius: 6px; background: #fff; }
.item-head { display: flex; align-items: center; justify-content: space-between; min-height: 45px; padding: 0 13px; border-bottom: 1px solid #eceef1; }
.item-head strong { display: flex; align-items: center; min-width: 0; font-size: 13px; font-weight: 600; }
.item-number { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; margin-right: 9px; border-radius: 50%; color: var(--admin-accent); background: #eeeeF7; font-size: 10px; flex: none; }
.item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-tools { display: flex; gap: 3px; flex: none; }
.icon-button { display: inline-flex; align-items: center; justify-content: center; width: 31px; height: 31px; padding: 0; border: 1px solid transparent; border-radius: 3px; color: #777b84; background: transparent; }
.icon-button:hover { color: var(--admin-accent); border-color: var(--admin-border); background: #fff; }
.icon-button:disabled { cursor: default; opacity: 0.3; }
.icon-button.is-danger:hover { color: var(--admin-danger); border-color: #edcccc; }
.item-fields { padding: 17px; }

.image-editor { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 14px; }
.image-preview { display: flex; align-items: center; justify-content: center; width: 132px; height: 88px; overflow: hidden; border: 1px solid var(--admin-border); border-radius: 4px; background: #f1f2f4; }
.image-preview img { width: 100%; height: 100%; object-fit: cover; }
.image-preview span { color: #a4a7ae; font-size: 11px; }
.image-controls { display: grid; align-content: start; gap: 8px; min-width: 0; }
.file-button { position: relative; display: inline-flex; align-items: center; justify-content: center; justify-self: start; min-height: 33px; gap: 6px; padding: 0 11px; overflow: hidden; border: 1px solid var(--admin-border); border-radius: 3px; color: #595d66; background: #fff; cursor: pointer; font-weight: 400; }
.file-button:hover { color: var(--admin-accent); border-color: #bdbdd8; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.empty-state { padding: 46px 20px; border: 1px dashed #cfd2d8; border-radius: 5px; color: #858992; background: #fafafa; text-align: center; }
.empty-state .glyphicon { display: block; margin-bottom: 12px; font-size: 24px; color: #adb0b7; }

.preview-pane {
  position: fixed;
  z-index: 20;
  right: 0;
  top: 68px;
  bottom: 0;
  width: var(--admin-preview);
  padding: 25px 20px;
  border-left: 1px solid var(--admin-border);
  background: #eef0f3;
}
.preview-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.preview-heading strong, .preview-heading small { display: block; }
.preview-heading strong { font-size: 13px; }
.preview-heading small { margin-top: 3px; color: #8a8e97; font-size: 10px; }
.preview-device { height: calc(100vh - 185px); min-height: 420px; overflow: hidden; border: 8px solid #2e3138; border-top-width: 26px; border-bottom-width: 26px; border-radius: 8px; background: #fff; box-shadow: 0 14px 30px rgba(35,38,45,.14); }
.preview-device iframe { width: 1280px; height: 2100px; border: 0; transform: scale(0.22); transform-origin: top left; }
.storage-note { margin: 16px 0 0; color: #858992; font-size: 10px; line-height: 1.5; text-align: center; }
.storage-note .glyphicon { margin-right: 5px; }

.toast { position: fixed; z-index: 100; right: 24px; bottom: 24px; max-width: 360px; padding: 11px 15px; border-radius: 4px; color: #fff; background: rgba(38, 41, 47, .95); opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.is-visible { opacity: 1; transform: translateY(0); }

@media (max-width: 1180px) {
  :root { --admin-preview: 300px; }
  .admin-shell { grid-template-columns: var(--admin-sidebar) minmax(430px, 1fr) var(--admin-preview); }
  .admin-main { padding-left: 26px; padding-right: 26px; }
}

@media (max-width: 960px) {
  .admin-shell { grid-template-columns: var(--admin-sidebar) minmax(0, 1fr); }
  .preview-pane { display: none; z-index: 60; left: 0; top: 68px; width: 100%; padding: 18px max(18px, calc((100vw - 420px) / 2)); }
  .preview-pane.is-open { display: block; }
  .preview-device { height: calc(100vh - 170px); }
  .mobile-preview { display: inline-flex; }
}

@media (max-width: 700px) {
  .admin-topbar { height: 62px; padding: 0 13px; }
  .admin-brand img { width: 142px; }
  .admin-brand > span, .save-status, .topbar-actions .btn-quiet { display: none; }
  .admin-shell { display: block; padding-top: 116px; }
  .admin-sidebar { top: 62px; right: 0; bottom: auto; width: 100%; height: 55px; padding: 5px 8px; border-right: 0; border-bottom: 1px solid var(--admin-border); overflow-x: auto; }
  .admin-sidebar nav { display: flex; width: max-content; gap: 2px; }
  .nav-item { display: inline-flex; width: auto; min-height: 43px; gap: 7px; padding: 0 11px; }
  .nav-item.is-active::before { left: 10px; right: 10px; bottom: -5px; width: auto; height: 2px; }
  .nav-item b, .sidebar-tools { display: none; }
  .admin-main { padding: 26px 16px 60px; }
  .editor-heading { margin-bottom: 20px; }
  .editor-heading h1 { font-size: 22px; }
  .form-grid, .visibility-list { grid-template-columns: 1fr; }
  .field.is-full { grid-column: auto; }
  .image-editor { grid-template-columns: 1fr; }
  .image-preview { width: 100%; height: auto; aspect-ratio: 16 / 7; }
  .item-fields { padding: 14px; }
  .preview-pane { top: 62px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; }
}
