:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e4e7ec;
  --text: #1f2329;
  --muted: #8a929c;
  --primary: #f97316;
  --primary-d: #ea580c;
  --danger: #e5484d;
  --ok: #2e9e5b;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.06);
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

/* 顶栏 */
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.icon-btn {
  border: none; background: transparent; font-size: 22px; line-height: 1;
  cursor: pointer; padding: 4px 8px; border-radius: 8px; color: var(--text);
}
.icon-btn:hover { background: #f0f2f5; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand .logo { font-size: 20px; }
.brand .title { font-size: 16px; }
.repo-info { margin-left: auto; color: var(--muted); font-size: 13px; padding-right: 8px; }
.top-actions { display: flex; gap: 8px; }

/* 按钮 */
.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: .15s;
}
.btn:hover { border-color: #c7ccd2; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 13px; }

/* 布局 */
.layout { display: flex; height: calc(100vh - 56px); }
/* 桌面端折叠侧边栏：释放横向空间，编辑区铺满 */
.layout.sidebar-collapsed .sidebar { width: 0; min-width: 0; border-right: none; padding: 0; }

.sidebar {
  width: 320px;
  min-width: 320px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .22s ease;
}
.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1; border: none; background: none; padding: 12px 6px;
  cursor: pointer; font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.list-tools { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--border); }
.list-tools input { flex: 1; min-width: 0; }

input[type=text], input[type=password], input[type=datetime-local], textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  outline: none;
  width: 100%;
}
input:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; }

.file-list { flex: 1; overflow-y: auto; padding: 6px; }
.file-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.file-item:hover { background: #f0f2f5; }
.file-item.active { background: #fff1e6; color: var(--primary-d); }
.file-item .fi-icon { width: 20px; text-align: center; flex: none; }
.file-item .fi-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item .fi-size { color: var(--muted); font-size: 11px; flex: none; }
.crumb { padding: 8px 12px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); word-break: break-all; }

/* 编辑区 */
.editor { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.empty-state { margin: auto; text-align: center; color: var(--muted); padding: 24px; }
.empty-state .big { font-size: 48px; }

.edit-form { display: flex; flex-direction: column; height: 100%; padding: 14px; gap: 12px; overflow: hidden; }
.edit-header { display: flex; gap: 10px; align-items: center; }
.edit-header .filename { flex: 1; min-width: 0; font-weight: 600; }
.edit-header .edit-status { margin-left: auto; max-width: 55%; text-align: right; }
.action-bar {
  position: sticky;
  bottom: 0;
  z-index: 6;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  margin: 0 -14px -14px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}
.action-bar .ab-spacer { flex: 1; }
.action-bar .btn.primary { min-width: 100px; font-weight: 600; }
.edit-status { font-size: 13px; min-height: 18px; color: var(--muted); }
.edit-status.ok { color: var(--ok); }
.edit-status.err { color: var(--danger); }

/* 文章字段 */
.post-fields {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 14px;
}
.post-fields .field { display: flex; flex-direction: column; gap: 4px; }
.post-fields label { font-size: 12px; color: var(--muted); }
.post-fields .full { grid-column: 1 / -1; }
.post-fields .field.checkbox { flex-direction: row; align-items: center; gap: 8px; }
.post-fields .field.checkbox input { width: auto; }

/* 动态字段 */
.dynamic-fields {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px;
}

/* 可折叠元信息面板（文章 / 动态字段） */
.meta-panel { border: 1px solid var(--border); border-radius: var(--radius); background: #fafbfc; overflow: hidden; }
.panel-head {
  width: 100%; box-sizing: border-box; border: none; background: none; cursor: pointer;
  padding: 11px 14px; font-size: 14px; font-weight: 600; color: var(--text);
  display: flex; align-items: center; justify-content: space-between; text-align: left;
}
.panel-head:hover { background: #f0f2f5; }
.panel-head .chev { color: var(--muted); font-size: 12px; transition: transform .18s ease; }
.meta-panel.collapsed .panel-head .chev { transform: rotate(-90deg); }
.panel-body { padding: 0 12px 12px; max-height: 40vh; overflow-y: auto; }
.meta-panel.collapsed .panel-body { display: none; }
.dynamic-fields .field { display: flex; flex-direction: column; gap: 4px; }
.dynamic-fields label { font-size: 12px; color: var(--muted); }

/* 编辑模式切换 */
.mode-switch { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.seg { border: 1px solid var(--border); background: #fff; padding: 5px 14px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.seg.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* 富文本编辑器宿主：填满剩余高度 */
.editor-host { flex: 1; min-height: 0; display: flex; }

/* 编辑主区：单栏（上传已移到左侧栏） */
.editor-main { flex: 1; min-height: 0; display: flex; }
/* 左侧栏上传面板的拖拽高亮 */
.meta-panel.drag { border-color: var(--primary); background: #fff4e9; }
.up-hint {
  font-size: 12px; color: var(--muted); line-height: 1.5; text-align: center;
  border: 1px dashed var(--border); border-radius: 8px; padding: 14px 8px;
}
.up-list { display: flex; flex-direction: column; gap: 8px; }
.up-item {
  display: flex; align-items: center; gap: 8px; padding: 6px;
  border: 1px solid var(--border); border-radius: 8px; background: #fff; font-size: 12px;
}
.up-item img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; flex: none; }
.up-item .up-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-item .up-insert {
  border: none; background: var(--primary); color: #fff; border-radius: 6px;
  padding: 4px 9px; cursor: pointer; font-size: 12px; flex: none;
}
.up-item .up-insert:hover { background: var(--primary-d); }
.up-item .up-err { color: var(--danger); font-size: 11px; }
#editor { flex: 1; min-height: 0; }
/* 让 ToastUI 默认 UI 占满高度并内部滚动 */
#editor .toastui-editor-defaultUI { height: 100%; }
#editor .toastui-editor-main { height: 100%; }
#editor .toastui-editor-md-container,
#editor .toastui-editor-ww-container { height: 100%; }
#editor .ProseMirror { min-height: 100%; }
#editor .toastui-editor-contents { min-height: 100%; }

.raw-editor { flex: 1; font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; font-size: 13px; line-height: 1.6; }

/* 弹窗 */
.modal-mask { position: fixed; inset: 0; background: rgba(20,24,30,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: #fff; width: 440px; max-width: 100%; border-radius: 14px; padding: 24px; box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.modal .hint { color: var(--muted); font-size: 13px; margin: 0 0 16px; line-height: 1.6; }
.modal label { display: block; font-size: 13px; margin: 12px 0 5px; color: #444; }
.modal input { width: 100%; }
.modal-actions { margin-top: 18px; }
.modal .err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 10px 0 0; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1f2329; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 14px; z-index: 60; box-shadow: var(--shadow); max-width: 90vw;
}

/* 移动端抽屉遮罩 */
.drawer-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(20,24,30,.35);
  z-index: 35;
}

/* 响应式 */
@media (max-width: 900px) {
  #menuBtn { display: inline-flex; }
  .layout { height: calc(100vh - 56px); }
  .sidebar {
    position: fixed; top: 56px; bottom: 0; left: 0; z-index: 40;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .drawer-backdrop.show { display: block; }
  .brand .title { display: none; }
  .editor { min-height: 0; }
  .post-fields, .dynamic-fields { grid-template-columns: 1fr; }
  .panel-body { max-height: 46vh; }
  .editor-main { flex-direction: column; }
  .edit-header { flex-wrap: wrap; }
}

@media (max-width: 560px) {
  .repo-info { display: none; }
  .edit-form { padding: 10px; gap: 10px; }
  .action-bar { padding: 10px; }
  .action-bar .btn { flex: 1; }
}

/* ===================== 登录页 ===================== */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(1200px 600px at 80% -10%, #ffe9d6 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #ffeede 0%, transparent 55%),
    linear-gradient(135deg, #fff6ee 0%, #f5f6f8 100%);
}
.login-wrap { width: 100%; max-width: 400px; }
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px 22px;
  box-shadow: var(--shadow);
}
.login-brand { text-align: center; margin-bottom: 22px; }
.login-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; font-size: 30px; border-radius: 16px;
  background: #fff1e6; margin-bottom: 12px;
}
.login-brand h1 { margin: 0; font-size: 20px; font-weight: 700; color: var(--text); }
.login-sub { margin: 6px 0 0; font-size: 13px; color: var(--muted); }

.login-form { display: flex; flex-direction: column; gap: 8px; }
.login-form label { font-size: 13px; color: #444; margin-top: 4px; }
.login-input-row { position: relative; display: flex; align-items: center; }
.login-input-row input { padding-right: 44px; }
.pwd-toggle {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  border: none; background: transparent; cursor: pointer; font-size: 16px;
  padding: 6px; border-radius: 8px; line-height: 1;
}
.pwd-toggle:hover { background: #f0f2f5; }
.btn.block { width: 100%; padding: 11px; font-size: 15px; font-weight: 600; letter-spacing: 2px; }
.btn.primary:disabled { opacity: .6; cursor: not-allowed; }

.login-form .err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 0; line-height: 1.5; }
.login-form .err.warn { color: #b45309; }

.login-foot {
  margin-top: 18px; text-align: center; font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--border); padding-top: 14px;
}
.login-foot .lock { margin-right: 4px; }

@media (max-width: 560px) {
  .login-card { padding: 26px 20px 18px; border-radius: 14px; }
  .login-brand h1 { font-size: 18px; }
}
