/* ==========================================================================
   管理后台样式
   ========================================================================== */

:root {
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #eef4ff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e5e9f2;
  --bg: #f6f8fc;
  --card: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.35; font-weight: 700; }
a { color: inherit; text-decoration: none; }
p { margin: 0 0 .6em; }
img { max-width: 100%; display: block; }
code { background: #f1f5f9; padding: .1em .4em; border-radius: 5px; font-size: .9em; }

/* ------------------------------- 按钮 ------------------------------- */
.btn,
.btn-primary,
.btn-ghost,
.btn-danger,
.btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: .55em 1em;
  font-family: inherit;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease, color .16s ease, box-shadow .16s ease;
  white-space: nowrap;
  background: #fff;
  color: var(--ink-2);
  border-color: var(--line);
}
.btn:hover, .btn-ghost:hover { border-color: #cbd5e1; background: #f8fafc; }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: 0 4px 12px rgba(37, 99, 235, .22); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { color: var(--danger); border-color: #fecaca; background: #fff5f5; }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: .3em .7em; font-size: .8rem; border-radius: 7px; }
.btn[disabled], .btn-primary[disabled], button[disabled] { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }

/* ------------------------------- 登录页 ------------------------------- */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(900px 480px at 15% 5%, #1e3a8a 0%, transparent 55%),
    radial-gradient(800px 460px at 90% 95%, #0e7490 0%, transparent 52%),
    linear-gradient(160deg, #0b1220, #101b30);
  padding: 24px;
}
.login-wrap { width: 100%; max-width: 410px; }
.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 36px 34px 30px;
  box-shadow: 0 30px 60px rgba(2, 8, 23, .35);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.login-brand { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 6px; }
.login-brand h1 { font-size: 1.2rem; }
.login-brand p { color: var(--muted); font-size: .82rem; margin: 2px 0 0; }
.brand-mark {
  width: 40px; height: 40px; flex: none;
  border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), #60a5fa);
  color: #fff; font-weight: 800; font-size: 1.1rem;
}
.login-tip { margin: 0; min-height: 1.2em; font-size: .84rem; color: var(--muted); }
.login-tip.is-err { color: var(--danger); }
.login-back { text-align: center; font-size: .84rem; color: var(--muted); }
.login-back:hover { color: var(--brand); }

/* ------------------------------- 布局 ------------------------------- */
.admin-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex: none;
  background: #0b1220;
  color: rgba(232, 238, 252, .78);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 20px; }
.sidebar-brand strong { display: block; color: #fff; font-size: .98rem; }
.sidebar-brand small { color: rgba(232, 238, 252, .5); font-size: .76rem; }

.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-link {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: .62em .8em;
  border: none; background: none;
  border-radius: 9px;
  color: rgba(232, 238, 252, .74);
  font-family: inherit; font-size: .88rem;
  cursor: pointer; text-align: left;
  transition: background .15s ease, color .15s ease;
  position: relative;
}
.side-link i { font-style: normal; width: 16px; text-align: center; opacity: .7; font-size: .92rem; }
.side-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.side-link.is-active { background: rgba(37, 99, 235, .22); color: #fff; font-weight: 600; }
.side-link.is-active i { opacity: 1; color: #93c5fd; }
.sidebar-foot { display: flex; flex-direction: column; gap: 2px; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, .07); }
.dot {
  width: 7px; height: 7px; border-radius: 50%; background: #f97316;
  margin-left: auto; display: none;
}
.dot.is-on { display: block; }

.admin-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 62px;
  display: flex; align-items: center; gap: 14px;
  padding: 0 26px;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 1.02rem; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.badge {
  font-size: .76rem; padding: .3em .8em; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand-dark); font-weight: 600;
  white-space: nowrap;
}
.badge.is-warn { background: #fff7ed; color: #c2410c; }
.badge.is-ok { background: #ecfdf5; color: #047857; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--ink); color: #fff;
  display: grid; place-items: center; font-size: .82rem; font-weight: 700;
}
.menu-btn {
  display: none;
  border: 1px solid var(--line); background: #fff;
  width: 36px; height: 36px; border-radius: 9px;
  font-size: 1rem; cursor: pointer;
}

.view { padding: 24px 26px 60px; display: flex; flex-direction: column; gap: 20px; }
.loading { padding: 60px; text-align: center; color: var(--muted); }

/* ------------------------------- 卡片 / 通用 ------------------------------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 16px;
}
.card-head h2 { font-size: .98rem; }
.card-head p { font-size: .82rem; color: var(--muted); margin: 2px 0 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }

.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.stat-card .num { font-size: 1.7rem; font-weight: 800; letter-spacing: -.02em; color: var(--brand); line-height: 1.2; }
.stat-card .label { color: var(--muted); font-size: .82rem; }

.empty {
  padding: 40px 20px; text-align: center; color: var(--muted);
  border: 1px dashed var(--line); border-radius: 12px;
}

/* ------------------------------- 表单 ------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span, .field-label { font-size: .82rem; font-weight: 600; color: var(--ink-2); }
.field input[type=text],
.field input[type=password],
.field input[type=email],
.field input[type=number],
.field input[type=url],
.field textarea,
.field select,
.form-field input[type=text],
.form-field textarea,
.form-field select {
  width: 100%;
  padding: .6em .8em;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-family: inherit; font-size: .88rem; color: var(--ink);
  background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field textarea, .form-field textarea { resize: vertical; min-height: 76px; line-height: 1.6; }
.field input:focus, .field textarea:focus, .field select:focus,
.form-field input:focus, .form-field textarea:focus, .form-field select:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.field-hint { font-size: .78rem; color: var(--muted); }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: .85rem; cursor: pointer; }
.switch input { width: auto; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }

/* ------------------------------- 页面 / 区块 ------------------------------- */
.page-list { display: flex; flex-direction: column; gap: 4px; }
.page-item {
  display: flex; align-items: center; gap: 8px;
  padding: .55em .7em; border-radius: 9px; cursor: pointer;
  border: 1px solid transparent; font-size: .88rem;
}
.page-item:hover { background: #f8fafc; }
.page-item.is-active { background: var(--brand-soft); border-color: #dbeafe; color: var(--brand-dark); font-weight: 600; }
.page-item .slug { margin-left: auto; font-size: .74rem; color: var(--muted); font-family: ui-monospace, monospace; }

.block-list { display: flex; flex-direction: column; gap: 10px; }
.block-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.block-item:hover { border-color: #c7d7f7; box-shadow: 0 4px 14px rgba(15, 23, 42, .05); }
.block-icon {
  width: 38px; height: 38px; flex: none;
  border-radius: 10px; background: var(--brand-soft);
  display: grid; place-items: center; font-size: 1.05rem;
}
.block-main { min-width: 0; flex: 1; }
.block-main strong { display: block; font-size: .9rem; }
.block-main small { color: var(--muted); font-size: .78rem; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.block-ops { display: flex; gap: 4px; flex-wrap: wrap; }
.icon-btn {
  width: 30px; height: 30px;
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  cursor: pointer; color: var(--ink-2); font-size: .82rem; line-height: 1;
  display: grid; place-items: center;
}
.icon-btn:hover { border-color: var(--brand); color: var(--brand); }
.icon-btn.danger:hover { border-color: #fca5a5; color: var(--danger); }
.icon-btn[disabled] { opacity: .35; cursor: not-allowed; }

.type-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.type-card {
  border: 1px solid var(--line); border-radius: 11px;
  padding: 16px 12px; text-align: center; cursor: pointer; background: #fff;
  transition: all .15s ease;
}
.type-card:hover { border-color: var(--brand); background: var(--brand-soft); transform: translateY(-2px); }
.type-card .ic { font-size: 1.5rem; display: block; margin-bottom: 6px; }
.type-card span { font-size: .82rem; }

/* ------------------------------- 媒体库 ------------------------------- */
.dropzone {
  border: 1.5px dashed #cbd5e1;
  border-radius: 12px;
  padding: 34px 20px;
  text-align: center;
  color: var(--muted);
  background: #fbfcff;
  cursor: pointer;
  transition: all .15s ease;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-dark); }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 12px; }
.media-item {
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  background: #fff; position: relative;
}
.media-item img { width: 100%; height: 108px; object-fit: cover; background: #f1f5f9; }
.media-item .meta { padding: 6px 8px; font-size: .72rem; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }
.media-item .meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-item .ops {
  position: absolute; top: 6px; right: 6px; display: flex; gap: 4px;
  opacity: 0; transition: opacity .15s ease;
}
.media-item:hover .ops { opacity: 1; }
.media-item .ops button {
  width: 26px; height: 26px; border-radius: 7px; border: none;
  background: rgba(15, 23, 42, .78); color: #fff; cursor: pointer; font-size: .72rem;
}
.media-item .ops button:hover { background: var(--brand); }

/* ------------------------------- 文章 / 留言 ------------------------------- */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: .76rem; color: var(--muted);
  font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line);
  text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
}
.table td { padding: 11px 10px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; font-size: .86rem; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #fbfdff; }
.table .title-cell { max-width: 460px; }
.table .title-cell a { font-weight: 600; }
.table .title-cell a:hover { color: var(--brand); }
.table .sub { color: var(--muted); font-size: .76rem; margin-top: 2px; }

.tag { font-size: .72rem; padding: .2em .6em; border-radius: 999px; background: #f1f5f9; color: var(--ink-2); font-weight: 600; }
.tag.wechat { background: #ecfdf5; color: #047857; }
.tag.rss { background: #fff7ed; color: #c2410c; }
.tag.unread { background: #fef2f2; color: #b91c1c; }

/* ------------------------------- 模态框 ------------------------------- */
.modal-root { position: fixed; inset: 0; z-index: 200; display: none; }
.modal-root.is-open { display: block; }
.modal-mask { position: absolute; inset: 0; background: rgba(8, 15, 32, .55); backdrop-filter: blur(2px); }
.modal {
  position: relative;
  width: min(100% - 32px, 720px);
  max-height: calc(100vh - 64px);
  margin: 32px auto;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 30px 70px rgba(2, 8, 23, .35);
  display: flex; flex-direction: column;
  animation: modalIn .2s ease;
}
.modal.is-wide { width: min(100% - 32px, 900px); }
@keyframes modalIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 22px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { font-size: 1rem; flex: 1; }
.modal-head .icon-btn { border: none; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot {
  padding: 14px 22px; border-top: 1px solid var(--line);
  display: flex; justify-content: flex-end; gap: 10px;
  background: #fcfdff; border-radius: 0 0 16px 16px;
}

/* ------------------------------- 区块表单 ------------------------------- */
.form-field { margin-bottom: 16px; }
.form-field > label, .form-field > .label {
  display: block; font-size: .82rem; font-weight: 600; color: var(--ink-2); margin-bottom: 6px;
}
.image-field { display: flex; gap: 8px; align-items: flex-start; }
.image-field input { flex: 1; }
.image-field .thumb {
  width: 46px; height: 46px; border-radius: 8px; object-fit: cover;
  border: 1px solid var(--line); background: #f8fafc; flex: none;
}
.list-field { display: flex; flex-direction: column; gap: 10px; }
.list-item {
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 12px 4px;
  background: #fcfdff; position: relative;
}
.list-item .item-ops { position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; }
.list-add { align-self: flex-start; }

/* ------------------------------- toast ------------------------------- */
.toast-root { position: fixed; top: 18px; right: 18px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 11px 16px; border-radius: 10px;
  background: #0f172a; color: #fff; font-size: .85rem;
  box-shadow: 0 10px 30px rgba(2, 8, 23, .3);
  animation: toastIn .2s ease;
  max-width: 420px;
  white-space: pre-line;
  line-height: 1.6;
}
.toast.is-err { background: #b91c1c; }
.toast.is-ok { background: #047857; }
@keyframes toastIn { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

/* ------------------------------- 响应式 ------------------------------- */
@media (max-width: 1100px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 60;
    transform: translateX(-100%); transition: transform .22s ease;
  }
  .sidebar.is-open { transform: none; }
  .menu-btn { display: grid; place-items: center; }
  .view { padding: 18px 16px 50px; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .type-grid { grid-template-columns: repeat(2, 1fr); }
  .table .hide-sm { display: none; }
}

/* ==========================================================================
   实时预览（区块编辑双栏）
   ========================================================================== */

.modal.is-xwide { width: min(100% - 32px, 1320px); }
.modal.is-xwide .modal-body { padding: 0; overflow: hidden; }

.edit-layout {
  display: grid;
  grid-template-columns: minmax(0, 400px) minmax(0, 1fr);
  height: min(74vh, 780px);
}
.edit-form {
  padding: 20px 22px 24px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
}
.edit-preview {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 14px 16px 12px;
  background: #f8fafd;
  overflow: hidden;
}
.preview-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  color: var(--muted);
}
.preview-bar .preview-label {
  font-weight: 600;
  color: var(--ink-2);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.preview-bar .preview-label::before {
  content: '';
  width: 7px; height: 7px; border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, .16);
}
.preview-bar .btn-sm.is-on {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-soft);
}
.preview-stage {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  padding: 12px;
  border-radius: 12px;
  background:
    linear-gradient(45deg, #eef2f9 25%, transparent 25%) -6px 0/12px 12px,
    linear-gradient(-45deg, #eef2f9 25%, transparent 25%) -6px 0/12px 12px,
    linear-gradient(45deg, transparent 75%, #eef2f9 75%) -6px 0/12px 12px,
    linear-gradient(-45deg, transparent 75%, #eef2f9 75%) -6px 0/12px 12px,
    #f6f8fc;
}
.preview-device {
  width: 100%;
  max-width: 100%;
  align-self: flex-start;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 18px rgba(15, 23, 42, .1);
  transition: width .22s ease;
}
.preview-device.is-mobile { width: 390px; }
#previewFrame {
  display: block;
  width: 100%;
  min-height: 240px;
  border: 0;
  background: #fff;
}
.preview-hint { font-size: .72rem; color: var(--muted); text-align: center; }

/* 服务器出口 IP */
.ip-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ip-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1rem;
  padding: .5em .9em;
  background: #f4f7fe;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  letter-spacing: .02em;
}

@media (max-width: 1080px) {
  .edit-layout { grid-template-columns: 1fr; height: auto; }
  .edit-form {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 46vh;
  }
  .edit-preview { height: 52vh; }
  .modal.is-xwide .modal-body { overflow-y: auto; }
}
