:root {
  color-scheme: light;
  --ink: #282923;
  --muted: #77786f;
  --paper: #f6f4ef;
  --white: #fff;
  --line: #dfddd5;
  --soft: #eeece5;
  --cinnabar: #9c3327;
  --cinnabar-dark: #7f281f;
  --jade: #426b5b;
  --gold: #a77a36;
  --danger: #b52d27;
  --shadow: 0 18px 55px rgb(46 42 32 / 14%);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--paper); min-width: 320px; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(90deg, transparent 49.8%, rgb(156 51 39 / 5%) 50%, transparent 50.2%), var(--paper); }
.login-panel { width: min(430px, 100%); background: var(--white); border: 1px solid var(--line); padding: 42px; box-shadow: var(--shadow); }
.login-panel h1 { font: 600 30px/1.2 "STKaiti", "KaiTi", serif; margin: 8px 0 12px; }
.seal { width: 68px; height: 68px; display: grid; place-items: center; color: white; background: var(--cinnabar); border: 3px double rgb(255 255 255 / 70%); font: 600 20px/1 "STKaiti", "KaiTi", serif; }
.seal.small { width: 46px; height: 46px; font-size: 15px; flex: 0 0 auto; }
.eyebrow { margin: 18px 0 0; color: var(--cinnabar); font-size: 11px; font-weight: 700; letter-spacing: 0; text-transform: uppercase; }
.muted { color: var(--muted); line-height: 1.7; }
label { display: grid; gap: 8px; color: #4d4e47; font-size: 13px; font-weight: 600; }
input, textarea, select { width: 100%; color: var(--ink); background: var(--white); border: 1px solid var(--line); border-radius: 3px; padding: 11px 12px; outline: none; transition: border-color .2s, box-shadow .2s; }
input:focus, textarea:focus, select:focus { border-color: var(--jade); box-shadow: 0 0 0 3px rgb(66 107 91 / 10%); }
textarea { resize: vertical; line-height: 1.6; }
.login-panel form { display: grid; gap: 16px; margin-top: 26px; }
.remember { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.remember input { width: 16px; height: 16px; }
.primary, .ghost, .danger-button, .icon-button { min-height: 40px; border: 1px solid transparent; border-radius: 3px; padding: 0 16px; font-weight: 600; }
.primary { color: white; background: var(--cinnabar); }
.primary:hover { background: var(--cinnabar-dark); }
.primary:disabled { opacity: .55; cursor: wait; }
.ghost { color: var(--ink); background: var(--white); border-color: var(--line); }
.ghost:hover { border-color: #aca99f; }
.danger-button { color: var(--danger); background: transparent; border-color: rgb(181 45 39 / 22%); }
.icon-button { color: var(--muted); background: transparent; padding: 0 8px; }
.full { width: 100%; }
.error-text { min-height: 20px; margin: 0; color: var(--danger); font-size: 13px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 240px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; color: #f5f1e8; background: #292c27; border-right: 4px solid var(--cinnabar); }
.brand { display: flex; align-items: center; gap: 13px; padding: 24px 20px 22px; border-bottom: 1px solid rgb(255 255 255 / 9%); }
.brand strong, .brand span { display: block; }
.brand strong { font: 600 19px/1.3 "STKaiti", "KaiTi", serif; }
.brand span { margin-top: 3px; color: #aaa99f; font-size: 11px; }
#navList { display: grid; gap: 3px; padding: 18px 12px; }
.nav-button { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 46px; padding: 0 13px; color: #c9c8bf; background: transparent; border: 0; border-radius: 3px; text-align: left; }
.nav-button:hover { color: white; background: rgb(255 255 255 / 6%); }
.nav-button.active { color: white; background: var(--cinnabar); }
.nav-button.sub-nav { min-height: 38px; padding-left: 30px; font-size: 12px; }
.nav-mark { width: 24px; color: #aaa99f; font: 600 15px/1 "STKaiti", "KaiTi", serif; text-align: center; }
.nav-button.active .nav-mark { color: white; }
.sidebar-note { margin-top: auto; padding: 18px 20px 24px; color: #999990; border-top: 1px solid rgb(255 255 255 / 8%); font-size: 11px; line-height: 1.7; }
.workspace { min-width: 0; padding: 32px 40px 56px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding-bottom: 25px; border-bottom: 1px solid var(--line); }
.topbar .eyebrow { margin: 0 0 5px; }
.topbar h1 { margin: 0; font: 600 27px/1.25 "STKaiti", "KaiTi", serif; }
.top-actions { display: flex; gap: 8px; }
.toolbar { display: flex; align-items: center; gap: 10px; padding: 23px 0 14px; }
.search-wrap { position: relative; flex: 0 1 360px; }
.search-wrap span { position: absolute; left: 13px; top: 8px; color: var(--muted); font-size: 20px; }
.search-wrap input { padding-left: 38px; }
.toolbar select { width: 130px; }
.toolbar .count { margin-left: auto; color: var(--muted); font-size: 12px; }
.table-shell { position: relative; min-height: 250px; overflow-x: auto; background: var(--white); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 13px 16px; color: var(--muted); background: #eceae3; border-bottom: 1px solid var(--line); font-size: 11px; text-align: left; }
td { padding: 15px 16px; border-bottom: 1px solid #ebe9e2; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #faf9f5; }
.title-cell strong, .title-cell span { display: block; max-width: 500px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-cell span { margin-top: 4px; color: var(--muted); font-size: 11px; }
.status-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 2px; font-size: 11px; }
.status-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-badge.published { color: var(--jade); background: rgb(66 107 91 / 10%); }
.status-badge.draft { color: #82734f; background: rgb(167 122 54 / 10%); }
.actions-column { width: 150px; text-align: right; }
.row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.text-button { min-height: 32px; color: var(--jade); background: transparent; border: 0; border-radius: 3px; padding: 0 8px; }
.text-button:hover { background: rgb(66 107 91 / 8%); }
.text-button.delete { color: var(--danger); }
.empty-state { position: absolute; inset: 43px 0 0; display: grid; place-content: center; justify-items: center; gap: 7px; color: var(--muted); background: var(--white); }
.empty-state strong { color: var(--ink); }
.empty-state span { font-size: 12px; }

.settings-view { width: min(940px, 100%); padding-top: 23px; }
.settings-section { margin-bottom: 16px; }
.section-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.settings-view .section-heading h3 { margin: 0 0 5px; }
.section-heading p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.settings-view textarea { min-height: 170px; }
.metric-settings { border-top: 1px solid var(--line); }
.metric-setting { display: grid; grid-template-columns: minmax(130px, .8fr) minmax(190px, 1fr) minmax(190px, 1fr) minmax(125px, .65fr); align-items: end; gap: 18px; padding: 20px 0; border-bottom: 1px solid var(--line); }
.metric-name { align-self: center; min-width: 0; }
.metric-name strong, .metric-name span { display: block; }
.metric-name strong { font: 600 16px/1.35 "STKaiti", "KaiTi", serif; }
.metric-name span { margin-top: 5px; color: var(--muted); font-size: 11px; }
.mode-segmented { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; padding: 3px; background: var(--soft); border: 1px solid var(--line); border-radius: 3px; }
.mode-option { position: relative; display: block; min-width: 0; font-weight: 400; }
.mode-option input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.mode-option span { min-height: 36px; display: grid; place-items: center; color: var(--muted); border-radius: 2px; font-size: 12px; white-space: nowrap; }
.mode-option input:checked + span { color: var(--cinnabar); background: var(--white); box-shadow: 0 1px 4px rgb(40 41 35 / 10%); font-weight: 700; }
.mode-option input:focus-visible + span { outline: 2px solid var(--jade); outline-offset: 1px; }
.manual-value-field { min-width: 0; transition: opacity .2s; }
.manual-value-field.is-disabled { opacity: .48; }
.manual-value-field input:disabled { cursor: not-allowed; background: var(--soft); }
.metric-auto-preview { min-height: 68px; display: grid; grid-template-columns: auto 1fr; align-content: center; column-gap: 8px; padding: 9px 12px; color: var(--muted); background: rgb(66 107 91 / 7%); border-left: 3px solid var(--jade); }
.metric-auto-preview span { grid-column: 1 / -1; font-size: 11px; }
.metric-auto-preview output { color: var(--jade); font: 600 25px/1.2 "STKaiti", "KaiTi", serif; }
.metric-auto-preview small { align-self: end; padding-bottom: 3px; font-size: 10px; }
.settings-actions { min-height: 68px; display: flex; align-items: center; justify-content: flex-end; gap: 18px; padding: 10px 0; }
.settings-hint { margin-right: auto; color: var(--muted); font-size: 12px; }
.category-settings-view { width: min(1120px, 100%); }
.category-table { overflow-x: auto; border: 1px solid var(--line); }
.category-table-header, .category-row { min-width: 890px; display: grid; grid-template-columns: minmax(170px, 1.2fr) minmax(190px, 1.35fr) 90px 115px 115px 80px; align-items: center; gap: 12px; padding: 12px 14px; }
.category-table-header { color: var(--muted); background: #eceae3; border-bottom: 1px solid var(--line); font-size: 11px; font-weight: 600; }
.category-rows { background: var(--white); }
.category-row { border-bottom: 1px solid #ebe9e2; }
.category-row:last-child { border-bottom: 0; }
.category-row:hover { background: #faf9f5; }
.category-field { min-width: 0; }
.category-field > span, .category-enabled > span, .category-usage > span, .category-action > span { display: none; }
.category-field input { padding: 9px 10px; }
.category-sort input { text-align: center; }
.category-enabled, .category-usage, .category-action { min-width: 0; }
.category-usage { display: flex; align-items: baseline; gap: 5px; color: var(--muted); }
.category-usage strong { color: var(--ink); font: 600 18px/1.2 "STKaiti", "KaiTi", serif; }
.category-usage small { font-size: 10px; }
.category-action { text-align: right; }
.category-action .text-button:disabled { color: #aaa89f; cursor: not-allowed; background: transparent; }
.category-empty-state { min-height: 180px; display: grid; place-content: center; justify-items: center; gap: 7px; color: var(--muted); background: var(--white); }
.category-empty-state strong { color: var(--ink); }
.category-empty-state span { font-size: 12px; }
.switch-control { display: flex; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
.switch-control input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch-control > span { position: relative; width: 38px; height: 22px; flex: 0 0 auto; background: #c8c6be; border-radius: 11px; transition: background .2s; }
.switch-control > span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; background: var(--white); border-radius: 50%; box-shadow: 0 1px 3px rgb(40 41 35 / 25%); transition: transform .2s; }
.switch-control input:checked + span { background: var(--jade); }
.switch-control input:checked + span::after { transform: translateX(16px); }
.switch-control input:focus-visible + span { outline: 2px solid var(--cinnabar); outline-offset: 2px; }
.switch-control b { min-width: 25px; color: var(--muted); font-size: 11px; font-weight: 600; }
.field-warning { color: var(--danger); }

.modal { position: fixed; inset: 0; z-index: 20; }
.modal-backdrop { position: absolute; inset: 0; background: rgb(27 28 25 / 55%); backdrop-filter: blur(2px); }
.editor-panel { position: absolute; inset: 0 0 0 auto; width: min(700px, 92vw); display: flex; flex-direction: column; background: var(--paper); box-shadow: -15px 0 50px rgb(0 0 0 / 16%); }
.editor-header { min-height: 82px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 26px; background: var(--white); border-bottom: 1px solid var(--line); }
.editor-header .eyebrow { margin: 0 0 5px; }
.editor-header h2 { margin: 0; font: 600 22px/1.3 "STKaiti", "KaiTi", serif; }
.close-button { width: 38px; height: 38px; color: var(--muted); background: transparent; border: 0; font-size: 25px; }
#editorForm { min-height: 0; flex: 1; display: flex; flex-direction: column; }
.editor-body { min-height: 0; flex: 1; overflow-y: auto; padding: 22px 26px 100px; }
.form-section { background: var(--white); border: 1px solid var(--line); padding: 22px; margin-bottom: 14px; }
.form-section h3 { margin: 0 0 18px; font: 600 17px/1.3 "STKaiti", "KaiTi", serif; }
.language-tabs { display: flex; gap: 1px; margin: 0 0 18px; border-bottom: 1px solid var(--line); }
.language-tab { position: relative; min-height: 37px; color: var(--muted); background: transparent; border: 0; padding: 0 18px; }
.language-tab.active { color: var(--cinnabar); font-weight: 700; }
.language-tab.active::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--cinnabar); }
.language-panel { display: grid; gap: 17px; }
.required { color: var(--danger); }
.form-grid { display: grid; gap: 16px; margin-top: 16px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
label small { color: var(--muted); font-weight: 400; }
.field-group { display: grid; gap: 10px; margin-top: 18px; }
.field-group > span { color: #4d4e47; font-size: 13px; font-weight: 600; }
.upload-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.upload-button { position: relative; display: grid; place-items: center; min-width: 100px; min-height: 42px; overflow: hidden; color: var(--jade); background: rgb(66 107 91 / 7%); border: 1px solid rgb(66 107 91 / 30%); border-radius: 3px; font-size: 12px; }
.upload-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-preview { display: flex; align-items: center; gap: 11px; min-height: 48px; margin-top: 8px; padding: 8px; background: var(--soft); border: 1px solid var(--line); }
.file-preview img, .file-preview video { width: 78px; height: 54px; object-fit: cover; background: #ddd; }
.file-preview a { min-width: 0; flex: 1; overflow: hidden; color: var(--jade); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.file-preview button { color: var(--danger); background: transparent; border: 0; }
.gallery-list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.gallery-item { position: relative; aspect-ratio: 1; overflow: hidden; border: 1px solid var(--line); }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; }
.gallery-item button { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; color: white; background: rgb(30 30 28 / 72%); border: 0; }
.gallery-add { position: relative; display: grid; place-items: center; aspect-ratio: 1; overflow: hidden; color: var(--jade); background: transparent; border: 1px dashed #aaa89f; font-size: 24px; }
.gallery-add input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.editor-footer { min-height: 70px; display: flex; align-items: center; justify-content: flex-end; gap: 9px; padding: 13px 26px; background: var(--white); border-top: 1px solid var(--line); }
.modal.compact { display: grid; place-items: center; padding: 20px; }
.import-panel, .password-panel { position: relative; width: min(520px, 100%); max-height: calc(100dvh - 40px); display: flex; flex-direction: column; overflow: hidden; background: var(--paper); box-shadow: var(--shadow); }
.password-panel { width: min(460px, 100%); }
#importForm, #passwordForm { min-height: 0; display: flex; flex-direction: column; }
.import-body, .password-body { min-height: 0; display: grid; gap: 20px; overflow-y: auto; padding: 24px; }
fieldset { display: grid; gap: 10px; margin: 0; padding: 14px; border: 1px solid var(--line); }
legend { padding: 0 6px; color: var(--muted); font-size: 12px; }
.radio-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px; background: var(--white); border: 1px solid var(--line); }
.radio-row input { width: 16px; margin-top: 3px; }
.radio-row span, .radio-row strong, .radio-row small { display: block; }
.radio-row small { margin-top: 3px; color: var(--muted); font-weight: 400; }
.warning { margin: 0; padding: 10px 12px; color: #725b2f; background: #f5eddb; font-size: 12px; line-height: 1.6; }
.toast { position: fixed; z-index: 50; right: 24px; bottom: 24px; max-width: min(380px, calc(100vw - 48px)); color: white; background: #292c27; border-left: 4px solid var(--jade); padding: 13px 18px; box-shadow: var(--shadow); font-size: 13px; }
.toast.error { border-left-color: var(--danger); }

@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 3px solid var(--cinnabar); }
  .brand { padding: 14px 18px; }
  #navList { display: flex; overflow-x: auto; padding: 8px 10px 11px; }
  .nav-button { width: auto; min-width: max-content; }
  .nav-button.sub-nav { min-height: 46px; padding-left: 13px; }
  .sidebar-note { display: none; }
  .workspace { padding: 22px 16px 40px; }
  .topbar { align-items: flex-start; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  .toolbar { flex-wrap: wrap; }
  .search-wrap { flex-basis: 100%; }
  .toolbar .count { margin-left: 0; }
  .toolbar .primary { margin-left: auto; }
  .form-grid.two { grid-template-columns: 1fr; }
  .settings-view { width: 100%; }
  .metric-setting { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
  .login-panel { padding: 28px 22px; }
  .topbar { display: block; }
  .top-actions { justify-content: flex-start; margin-top: 16px; }
  .editor-panel { width: 100vw; }
  .editor-header, .editor-body, .editor-footer { padding-left: 16px; padding-right: 16px; }
  .form-section { padding: 16px; }
  .metric-setting { grid-template-columns: 1fr; gap: 13px; }
  .metric-name { padding-top: 3px; }
  .settings-actions { align-items: stretch; flex-direction: column; }
  .settings-hint { margin-right: 0; line-height: 1.6; }
  .settings-actions .primary { width: 100%; }
  .category-table { overflow: visible; border: 0; }
  .category-table-header { display: none; }
  .category-row { min-width: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; margin-bottom: 10px; padding: 16px; background: var(--white); border: 1px solid var(--line); }
  .category-field:first-child, .category-field:nth-child(2) { grid-column: 1 / -1; }
  .category-field > span, .category-enabled > span, .category-usage > span, .category-action > span { display: block; margin-bottom: 7px; color: #4d4e47; font-size: 11px; font-weight: 600; }
  .category-usage { display: block; }
  .category-usage strong, .category-usage small { display: inline; }
  .category-action { text-align: left; }
  .category-action .text-button { padding: 0; }
  .gallery-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .modal.compact { place-items: start center; padding: 12px; }
  .import-panel, .password-panel { max-height: calc(100dvh - 24px); }
}
