:root {
  color-scheme: light;
  --bg: #f5f7f5;
  --surface: #ffffff;
  --surface-soft: #eef2ef;
  --text: #1c2420;
  --muted: #69736e;
  --line: #dce3de;
  --accent: #116f62;
  --accent-strong: #0a5148;
  --accent-soft: #dcefe9;
  --danger: #a33b3b;
  --danger-soft: #fbe9e9;
  --warning: #a15a13;
  --warning-soft: #fff0df;
  --code: #151d1a;
  --topbar: 58px;
  --sidebar: 292px;
  --shadow: 0 12px 32px rgba(22, 37, 31, .1);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-width: 320px; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  letter-spacing: 0;
}
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(90deg, transparent 49.8%, rgba(17,111,98,.05) 50%, transparent 50.2%),
    linear-gradient(rgba(17,111,98,.04) 1px, transparent 1px);
  background-size: 100% 100%, 100% 36px;
}

.login-panel {
  width: min(100%, 390px);
  display: grid;
  gap: 18px;
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-mark, .admin-mark {
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--text);
  color: white;
  font-family: Georgia, serif;
  font-weight: 700;
}
.login-mark { width: 44px; height: 44px; font-size: 22px; }
.login-panel h1 { margin: 0; font-size: 23px; letter-spacing: 0; }
.login-panel p { margin: 4px 0 0; color: var(--muted); }
label { display: grid; gap: 6px; }
label > span { color: var(--muted); font-size: 12px; font-weight: 700; }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: 0;
  background: var(--surface);
  color: var(--text);
}
input, select { height: 38px; padding: 0 11px; }
textarea { padding: 9px 11px; resize: vertical; }
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-error { min-height: 20px; color: var(--danger); font-size: 12px; }
.quiet-link { color: var(--muted); font-size: 12px; text-align: center; text-underline-offset: 3px; }

.primary-button, .secondary-button, .danger-button, .text-button {
  min-height: 36px;
  padding: 0 14px;
  border-radius: 6px;
  font-weight: 700;
}
.primary-button { border: 1px solid var(--accent); background: var(--accent); color: white; }
.primary-button:hover { background: var(--accent-strong); }
.secondary-button { border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.secondary-button:hover { border-color: var(--accent); color: var(--accent); }
.danger-button { border: 1px solid var(--danger-soft); background: var(--surface); color: var(--danger); }
.danger-button:hover { background: var(--danger-soft); }
.text-button { border: 0; background: transparent; color: var(--muted); }
.text-button:hover { color: var(--text); }
.full-button { width: 100%; }
.compact { min-height: 32px; padding: 0 10px; font-size: 12px; }

.admin-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  grid-template-rows: var(--topbar) minmax(0, 1fr);
}
.admin-topbar {
  grid-column: 1 / -1;
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar);
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr) auto;
  align-items: center;
  gap: 20px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.admin-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
}
.admin-mark { width: 32px; height: 32px; }
.admin-brand > span:last-child { display: grid; line-height: 1.2; }
.admin-brand strong { font-size: 13px; }
.admin-brand small { margin-top: 2px; color: var(--muted); font-size: 9px; text-transform: uppercase; }
.save-state { color: var(--muted); font-size: 12px; }
.save-state.dirty { color: var(--warning); }
.save-state.saving { color: var(--accent); }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.icon-button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-decoration: none;
}
.icon-button:hover { border-color: var(--line); background: var(--surface-soft); }

.admin-sidebar {
  grid-column: 1;
  grid-row: 2;
  position: sticky;
  top: var(--topbar);
  height: calc(100vh - var(--topbar));
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--surface);
  overflow: hidden;
}
.sidebar-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 14px 10px;
}
.sidebar-toolbar > div { display: grid; }
.sidebar-toolbar strong { font-size: 13px; }
.sidebar-toolbar small { color: var(--muted); font-size: 10px; }
.list-filters { display: grid; grid-template-columns: minmax(0, 1fr) 104px; gap: 7px; padding: 0 12px 12px; }
.list-filters input, .list-filters select { height: 34px; font-size: 12px; }
.admin-article-list { min-height: 0; flex: 1; padding: 0 8px 20px; overflow-y: auto; }
.admin-list-item {
  width: 100%;
  display: grid;
  grid-template-columns: 7px minmax(0, 1fr);
  gap: 9px;
  padding: 11px 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
}
.admin-list-item:hover { background: var(--surface-soft); }
.admin-list-item.active { background: var(--accent-soft); }
.list-status { width: 7px; height: 7px; margin-top: 6px; border-radius: 50%; background: var(--muted); }
.list-status.published { background: #2a9d72; }
.list-status.draft { background: #d18b32; }
.list-status.archived { background: #919995; }
.list-copy { min-width: 0; display: grid; }
.list-copy strong { overflow: hidden; font-size: 12.5px; text-overflow: ellipsis; white-space: nowrap; }
.list-copy small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.list-empty { padding: 40px 12px; color: var(--muted); text-align: center; }

.editor-view { grid-column: 2; grid-row: 2; min-width: 0; }
.empty-editor { min-height: calc(100vh - var(--topbar)); display: grid; align-content: center; justify-items: center; gap: 5px; color: var(--muted); text-align: center; }
.empty-editor strong { color: var(--text); }
.article-editor { min-height: calc(100vh - var(--topbar)); }
.editor-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.editor-header > div:first-child { min-width: 0; display: flex; align-items: center; gap: 10px; }
.editor-header h1 { margin: 0; overflow: hidden; font-size: 16px; text-overflow: ellipsis; white-space: nowrap; }
.status-badge { padding: 3px 7px; border-radius: 5px; font-size: 10px; font-weight: 700; white-space: nowrap; }
.status-badge.published { background: var(--accent-soft); color: var(--accent-strong); }
.status-badge.draft { background: var(--warning-soft); color: var(--warning); }
.status-badge.archived { background: var(--surface-soft); color: var(--muted); }
.editor-actions { display: flex; gap: 7px; }

.metadata-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.wide-field { grid-column: span 2; }
.metadata-grid textarea { min-height: 62px; }

.editor-workspace {
  height: calc(100vh - var(--topbar) - 72px - 184px);
  min-height: 480px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
.write-pane, .preview-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--surface); }
.write-pane { border-right: 1px solid var(--line); }
.pane-toolbar {
  height: 42px;
  flex: 0 0 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.pane-toolbar > div { display: flex; gap: 3px; }
.tool-button { min-width: 28px; height: 28px; padding: 0 7px; border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--text); font-size: 11px; }
.tool-button:hover { border-color: var(--line); background: var(--surface-soft); }
#contentInput {
  min-height: 0;
  flex: 1;
  padding: 18px;
  border: 0;
  border-radius: 0;
  background: #fbfcfb;
  font: 13px/1.7 ui-monospace, SFMono-Regular, Consolas, monospace;
  resize: none;
  box-shadow: none;
}
.admin-preview { min-height: 0; flex: 1; padding: 22px clamp(20px, 4vw, 44px) 60px; overflow-y: auto; }
.admin-preview h1 { margin: 0 0 8px; font-size: 29px; line-height: 1.25; }
.admin-preview .preview-description { margin: 0 0 25px; color: var(--muted); }
.admin-preview h2 { margin: 34px 0 12px; font-size: 21px; }
.admin-preview h3 { margin: 26px 0 10px; font-size: 17px; }
.admin-preview p { margin: 0 0 15px; }
.admin-preview ul, .admin-preview ol { padding-left: 22px; }
.admin-preview blockquote { margin: 18px 0; padding: 13px 16px; border-left: 4px solid var(--accent); background: var(--accent-soft); }
.admin-preview :not(pre) > code { padding: 2px 5px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface-soft); color: var(--accent-strong); }
.admin-preview pre { margin: 18px 0; padding: 16px; border-radius: 7px; background: var(--code); color: #e6efeb; overflow-x: auto; }
.admin-preview pre code { font: 12px/1.65 ui-monospace, SFMono-Regular, Consolas, monospace; }
.admin-preview table { width: 100%; margin: 18px 0; border-collapse: collapse; font-size: 12px; }
.admin-preview th, .admin-preview td { padding: 8px 10px; border: 1px solid var(--line); text-align: left; }
.admin-preview th { background: var(--surface-soft); }
.admin-preview img { display: block; max-width: 100%; max-height: 560px; margin: 20px auto; border: 1px solid var(--line); border-radius: 7px; }
.preview-empty { padding: 70px 10px; color: var(--muted); text-align: center; }
.mobile-editor-tabs { display: none; }

.history-dialog, .password-dialog {
  width: min(92vw, 560px);
  max-height: 72vh;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.history-dialog::backdrop, .password-dialog::backdrop { background: rgba(11, 18, 15, .5); }
.history-dialog header, .password-dialog header { display: flex; align-items: center; justify-content: space-between; padding: 15px 17px; border-bottom: 1px solid var(--line); }
.history-dialog header > div, .password-dialog header > div { display: grid; }
.history-dialog header small, .password-dialog header small { color: var(--muted); font-size: 10px; }
.revision-list { max-height: 58vh; padding: 8px; overflow-y: auto; }
.revision-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 11px; border-bottom: 1px solid var(--line); }
.revision-copy { display: grid; }
.revision-copy strong { font-size: 12px; }
.revision-copy small { color: var(--muted); font-size: 10px; }
.dialog-form { display: grid; gap: 13px; padding: 18px; }
.password-dialog footer { display: flex; justify-content: flex-end; gap: 7px; padding: 12px 18px; border-top: 1px solid var(--line); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 100;
  padding: 9px 14px;
  border-radius: 6px;
  background: var(--text);
  color: white;
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: 160ms ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1050px) {
  .admin-shell { grid-template-columns: 250px minmax(0, 1fr); }
  .admin-topbar { grid-template-columns: 250px minmax(0, 1fr) auto; }
  .metadata-grid { grid-template-columns: 1fr 1fr; }
  .wide-field { grid-column: span 2; }
  .editor-workspace { height: auto; min-height: 650px; }
}

@media (max-width: 760px) {
  .admin-shell { display: block; padding-top: var(--topbar); }
  .admin-topbar { position: fixed; grid-template-columns: minmax(0, 1fr) auto; width: 100%; gap: 8px; }
  .admin-brand small, .save-state, .topbar-actions .icon-button:first-child { display: none; }
  .admin-sidebar { position: static; width: 100%; height: 300px; border-right: 0; border-bottom: 1px solid var(--line); }
  .editor-view { min-width: 0; }
  .empty-editor { min-height: 400px; }
  .editor-header { align-items: flex-start; flex-direction: column; }
  .editor-actions { width: 100%; overflow-x: auto; }
  .editor-actions button { flex: 0 0 auto; }
  .metadata-grid { grid-template-columns: 1fr; padding: 14px; }
  .wide-field { grid-column: span 1; }
  .mobile-editor-tabs { display: flex; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--surface); }
  .mobile-editor-tabs button { flex: 1; height: 34px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); }
  .mobile-editor-tabs button:first-child { border-radius: 6px 0 0 6px; }
  .mobile-editor-tabs button:last-child { border-radius: 0 6px 6px 0; }
  .mobile-editor-tabs button.active { background: var(--accent-soft); color: var(--accent-strong); }
  .editor-workspace { display: block; min-height: 620px; }
  .editor-workspace[data-mobile-pane="write"] .preview-pane { display: none; }
  .editor-workspace[data-mobile-pane="preview"] .write-pane { display: none; }
  .write-pane, .preview-pane { height: 620px; border-right: 0; }
}
