:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --ink: #171717;
  --muted: #777;
  --line: #e5e5e3;
  --soft: #f6f6f4;
  --blue: #245dff;
  --red: #c52b3a;
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: #fff; font-size: 14px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.login-page { min-height: 100vh; padding: 28px; display: grid; place-items: center; background: #f5f5f2; }
.login-card { width: min(420px, 100%); padding: 34px; background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 18px 50px rgba(0,0,0,.08); }
.admin-brand { display: flex; align-items: center; gap: 11px; }
.admin-brand-mark { width: 34px; height: 34px; display: grid; place-items: center; color: #fff; background: #171717; border-radius: 9px; font-weight: 800; }
.admin-brand div { display: flex; flex-direction: column; line-height: 1.25; }
.admin-brand strong { font-size: 15px; }
.admin-brand small { color: #888; font-size: 11px; }
.login-card h1 { margin: 34px 0 5px; font-size: 27px; letter-spacing: -.03em; }
.login-card > p { margin: 0 0 24px; color: var(--muted); line-height: 1.6; }
label { display: flex; flex-direction: column; gap: 7px; color: #555; font-size: 12px; font-weight: 620; }
input, select, textarea { color: #222; background: #fff; border: 1px solid #d9d9d6; border-radius: 8px; outline: 0; }
input, select { height: 39px; padding: 0 10px; }
input:focus, select:focus, textarea:focus { border-color: #6f8ce9; box-shadow: 0 0 0 3px rgba(36,93,255,.1); }
.primary-button { min-height: 39px; padding: 0 15px; color: #fff; background: #171717; border: 1px solid #171717; border-radius: 8px; font-weight: 620; }
.primary-button:hover { background: #333; }
.primary-button:disabled { opacity: .5; cursor: not-allowed; }
.login-card .primary-button { width: 100%; margin-top: 4px; }
.form-error { min-height: 22px; padding: 5px 0; color: var(--red); font-size: 12px; font-weight: 500; }
.back-link { margin-top: 22px; display: inline-block; color: #777; text-decoration: none; font-size: 12px; }
.back-link:hover { color: #222; }

.admin-page { height: 100vh; overflow: hidden; background: #f7f7f5; }
.admin-header { height: 58px; padding: 0 20px; display: flex; align-items: center; justify-content: space-between; background: #fff; border-bottom: 1px solid var(--line); }
.admin-header-actions { display: flex; align-items: center; gap: 5px; }
.admin-header-actions a, .text-button { padding: 7px 9px; color: #666; background: transparent; border: 0; border-radius: 6px; text-decoration: none; font-size: 12px; }
.admin-header-actions a:hover, .text-button:hover { color: #111; background: var(--soft); }
.admin-shell { height: calc(100vh - 58px); display: grid; grid-template-columns: 270px minmax(0, 1fr); }
.admin-sidebar { min-width: 0; background: #fff; border-right: 1px solid var(--line); overflow-y: auto; }
.sidebar-toolbar { position: sticky; top: 0; z-index: 2; height: 54px; padding: 0 14px 0 17px; display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,255,.95); border-bottom: 1px solid var(--line); }
.sidebar-toolbar strong { font-size: 13px; }
.sidebar-toolbar button { padding: 5px 7px; color: #666; background: #fff; border: 1px solid #ddd; border-radius: 6px; font-size: 11px; }
.sidebar-toolbar button:hover { color: #111; border-color: #aaa; }
.admin-tree { padding: 12px 10px 50px; }
.tree-group { margin-bottom: 18px; }
.tree-group-header { padding: 4px 8px 6px; display: flex; align-items: center; justify-content: space-between; color: #888; }
.tree-group-header strong { font-size: 11px; letter-spacing: .04em; }
.tree-group-header button { padding: 2px 4px; color: #aaa; background: transparent; border: 0; font-size: 11px; }
.tree-document { width: 100%; margin: 1px 0; padding: 8px 9px; display: flex; align-items: center; gap: 7px; color: #4f4f4f; background: transparent; border: 0; border-radius: 7px; text-align: left; font-size: 12px; }
.tree-document:hover { color: #111; background: var(--soft); }
.tree-document.active { color: #111; background: #ececea; font-weight: 620; }
.status-dot { width: 6px; height: 6px; flex: 0 0 auto; background: #bbb; border-radius: 50%; }
.status-dot.published { background: #27a05a; }
.tree-document span:nth-child(2) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.editor { min-width: 0; height: 100%; background: #fff; overflow: hidden; }
.editor[hidden] { display: none; }
.empty-state { height: 100%; display: grid; place-content: center; justify-items: center; color: #888; text-align: center; }
.empty-state > span { width: 48px; height: 48px; display: grid; place-items: center; color: #aaa; background: var(--soft); border-radius: 14px; font-size: 23px; }
.empty-state h1 { margin: 18px 0 5px; color: #444; font-size: 19px; }
.empty-state p { margin: 0; font-size: 13px; }
.editor-toolbar { height: 54px; padding: 0 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.editor-toolbar > div { display: flex; align-items: center; gap: 8px; }
.save-state { color: #999; font-size: 11px; }
.save-state.dirty { color: #b57516; }
.save-state.saved { color: #278b52; }
.danger-button { min-height: 35px; padding: 0 11px; color: var(--red); background: #fff; border: 1px solid #ead1d4; border-radius: 7px; font-size: 12px; }
.danger-button:hover { background: #fff6f7; }
.editor-toolbar .primary-button { min-height: 35px; font-size: 12px; }
.document-fields { min-height: 74px; padding: 12px 18px; display: grid; grid-template-columns: minmax(150px, 1.3fr) minmax(180px, 1.3fr) minmax(130px, .8fr) 80px auto auto; align-items: end; gap: 10px; border-bottom: 1px solid var(--line); }
.document-fields input, .document-fields select { width: 100%; height: 34px; font-size: 12px; }
.check-field { height: 34px; display: flex; flex-direction: row; align-items: center; gap: 6px; white-space: nowrap; }
.check-field input { width: 16px; height: 16px; padding: 0; }
.editor-tabs { height: 44px; padding: 0 18px; display: flex; align-items: end; gap: 2px; border-bottom: 1px solid var(--line); }
.editor-tabs > button { height: 43px; padding: 0 13px; color: #777; background: transparent; border: 0; border-bottom: 2px solid transparent; font-size: 12px; }
.editor-tabs > button.active { color: #111; border-bottom-color: #111; font-weight: 620; }
.upload-button { height: 30px; margin: 0 0 6px auto; padding: 0 10px; display: flex; align-items: center; color: #666; background: #fff; border: 1px solid #ddd; border-radius: 6px; cursor: pointer; font-size: 11px; font-weight: 500; }
.upload-button:hover { color: #111; border-color: #aaa; }
.upload-button input { display: none; }
.editor-panes { height: calc(100% - 172px); min-height: 0; }
.editor-panes textarea { width: 100%; height: 100%; padding: 26px 30px 70px; resize: none; border: 0; border-radius: 0; box-shadow: none; font: 14px/1.7 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; tab-size: 2; }
.editor-preview { height: 100%; padding: 30px max(36px, 8vw) 80px; overflow-y: auto; }
.editor-preview[hidden] { display: none; }

.markdown-body { max-width: 820px; margin: 0 auto; color: #333; font-size: 15px; line-height: 1.7; }
.markdown-body > :first-child { margin-top: 0; }
.markdown-body h1 { margin: 0 0 24px; color: #111; font-size: 34px; letter-spacing: -.03em; }
.markdown-body h2 { margin: 42px 0 15px; color: #111; font-size: 24px; }
.markdown-body h3 { margin: 30px 0 12px; color: #111; font-size: 19px; }
.markdown-body code { padding: 2px 5px; color: #bd2748; background: #f3f3f1; border-radius: 4px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.markdown-body pre { padding: 18px; color: #e8e8e8; background: #171717; border-radius: 10px; overflow: auto; }
.markdown-body pre code { padding: 0; color: inherit; background: transparent; }
.markdown-body blockquote { margin: 20px 0; padding: 11px 16px; background: #f4f7ff; border-left: 3px solid var(--blue); }
.markdown-body table { width: 100%; border-collapse: collapse; }
.markdown-body th, .markdown-body td { padding: 9px 12px; border: 1px solid #ddd; text-align: left; }
.markdown-body img { max-width: 100%; border-radius: 10px; }

.toast { position: fixed; z-index: 30; right: 20px; bottom: 20px; max-width: 360px; padding: 11px 14px; color: #fff; background: #222; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.2); font-size: 12px; }
.toast.error { background: #9f2430; }
.toast[hidden] { display: none; }
dialog { padding: 0; border: 0; border-radius: 14px; box-shadow: 0 24px 90px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.36); backdrop-filter: blur(2px); }
.dialog-card { width: min(410px, calc(100vw - 32px)); padding: 24px; display: grid; gap: 15px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; }
.dialog-heading h2 { margin: 0; font-size: 18px; }
.dialog-heading button { width: 30px; height: 30px; background: transparent; border: 0; border-radius: 6px; font-size: 20px; }
.dialog-heading button:hover { background: var(--soft); }
.dialog-card label small { color: #999; font-weight: 400; }

@media (max-width: 1050px) {
  .document-fields { grid-template-columns: 1fr 1fr 140px 70px; }
  .check-field { align-self: center; }
}
@media (max-width: 760px) {
  .admin-header { padding-inline: 12px; }
  .admin-header-actions a { display: none; }
  .admin-shell { grid-template-columns: 190px minmax(0, 1fr); }
  .document-fields { grid-template-columns: 1fr 1fr; max-height: 150px; overflow-y: auto; }
  .editor-panes { height: calc(100% - 248px); }
  .editor-panes textarea { padding: 20px; }
}
