:root {
  --bg: #f4efe7;
  --panel: #fffaf4;
  --sidebar: #171411;
  --sidebar-2: #221e1a;
  --text: #2b241c;
  --muted: #8a7d6f;
  --line: #eadfce;
  --coral: #e36b5b;
  --coral-dark: #c84f40;
  --gold: #c4a574;
  --ok: #2f9d6a;
  --danger: #c4473a;
  --shadow: 0 18px 40px rgba(43, 36, 28, 0.08);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
@font-face {
  font-family: "Noto Sans SC";
  src: url("/fonts/NotoSansSC-Regular.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Noto Sans SC";
  src: url("/fonts/NotoSansSC-Bold.woff") format("woff");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Noto Serif SC";
  src: url("/fonts/NotoSerifSC-Regular.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Noto Serif SC";
  src: url("/fonts/NotoSerifSC-Bold.woff") format("woff");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
body {
  font-family: "Noto Sans SC", "Source Han Sans SC", sans-serif;
  color: var(--text);
  background: var(--bg);
  letter-spacing: 0.02em;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(227, 107, 91, 0.16), transparent 28%),
    linear-gradient(180deg, #f7f1e8 0%, #efe4d4 100%);
}

.login-card {
  width: min(420px, calc(100% - 32px));
  background: #fffaf4;
  border: 1px solid #eadfce;
  border-radius: 28px;
  padding: 42px 36px;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-mark, .brand-mark {
  width: 54px;
  height: 54px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #f08a7c, #d75a4b);
  color: #fff;
  font-weight: 700;
  margin: 0 auto 16px;
}

.login-card h1 { margin: 0; font-size: 28px; }
.login-card p { color: var(--muted); margin: 8px 0 28px; }
.login-card .icp { margin: 18px 0 0; font-size: 12px; text-align: center; }
.login-card .icp a { color: var(--muted); text-decoration: none; }
.login-card form { text-align: left; display: grid; gap: 16px; }
label { display: grid; gap: 8px; font-size: 13px; color: var(--muted); }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 12px 14px;
  color: var(--text);
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: #e3b8af; box-shadow: 0 0 0 4px rgba(227, 107, 91, 0.12); }
.login-card button, .primary-btn, .ghost-btn, .danger-btn, .mini-btn {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  white-space: nowrap;
}
.login-card button, .primary-btn {
  background: linear-gradient(180deg, #ee7d6e, #d85a4b);
  color: #fff;
  font-weight: 600;
}
.ghost-btn { background: #f4ebe0; color: var(--text); }
.danger-btn, .mini-btn.danger { background: #f8e4e0; color: var(--danger); }
.mini-btn { padding: 8px 12px; font-size: 12px; background: #f4ebe0; }
.mini-btn:disabled { opacity: 0.38; cursor: not-allowed; }
.sort-cell { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.sort-num { min-width: 1.4em; font-weight: 700; }
.form-hint { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.form-error { color: var(--danger); min-height: 20px; font-size: 13px; }

.app {
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  overflow-x: hidden;
}

.sidebar {
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  color: #f7efe6;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand { display: flex; gap: 12px; align-items: center; padding: 0 10px; }
.brand-mark { margin: 0; width: 44px; height: 44px; border-radius: 14px; }
.brand strong { display: block; font-size: 16px; }
.brand small { color: #b9a894; }

nav { display: grid; gap: 6px; }
nav button {
  text-align: left;
  background: transparent;
  color: #d8c8b5;
  border: 0;
  border-radius: 14px;
  padding: 12px 14px;
}
nav button.active, nav button:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}
nav button.active { box-shadow: inset 3px 0 0 var(--coral); }

.sidebar-foot {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  color: #cbbba8;
}
.sidebar-foot button {
  background: transparent;
  color: #f3d2cb;
  border: 1px solid rgba(243, 210, 203, 0.3);
  border-radius: 999px;
  padding: 6px 12px;
}

.main {
  min-width: 0;
  padding: 28px 32px 48px;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.topbar > div { min-width: 0; flex: 1; }
.topbar h2 { margin: 0; font-size: 28px; }
.topbar p { margin: 6px 0 0; color: var(--muted); line-height: 1.5; }
#primary-action { flex-shrink: 0; }

.page-root { display: grid; gap: 20px; min-width: 0; }
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}
.stat, .card, table {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  min-width: 0;
  max-width: 100%;
}
.stat { padding: 20px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat strong { display: block; font-size: 30px; margin-top: 10px; }

.toolbar, .form-grid { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.toolbar label, .form-grid label { min-width: 140px; flex: 1 1 160px; }
.toolbar button { flex: 0 0 auto; }
.card { padding: 20px; }
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.section-head strong { display: block; color: var(--text); }
.section-head span { color: var(--muted); font-size: 13px; }
.category-list { display: grid; gap: 10px; }
.category-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
}
.category-item strong { flex: 1; min-width: 0; }
.category-item .sort-cell { margin-left: auto; flex-shrink: 0; }
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 16px 4px;
}
.filter-chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
}
.filter-chip em {
  font-style: normal;
  margin-left: 6px;
  color: var(--muted);
}
.filter-chip.active {
  background: #2b241c;
  color: #fffaf4;
  border-color: #2b241c;
}
.filter-chip.active em { color: rgba(255,250,244,0.72); }
table { width: 100%; border-collapse: collapse; overflow: hidden; }
th, td { padding: 14px 16px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; }
th:last-child, td:last-child { white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: #fbf6ef; }
.tag {
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  background: #f4ebe0;
}
.tag.ok { background: #e5f6ee; color: var(--ok); }
.tag.warn { background: #fde8e4; color: var(--coral-dark); }
.code { font-family: "Noto Sans SC", "Source Han Sans SC", sans-serif; letter-spacing: 0.6px; word-break: break-all; }
.code-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.code-text {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-align: left;
  cursor: pointer;
}
.code-text:hover { color: var(--coral-dark, #c4473a); }
.code-row .mini-btn { flex-shrink: 0; }

.editor { display: grid; gap: 16px; }
.editor textarea { min-height: 280px; resize: vertical; }
.article-content-sync { display: none !important; }
.article-editor {
  min-height: 360px;
  max-height: 72vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 16px;
  background: #fff;
  color: #2b241c;
  line-height: 1.9;
  letter-spacing: 0.35px;
  outline: none;
  font-family: "Noto Sans SC", "Source Han Sans SC", sans-serif;
}
.article-editor:focus {
  border-color: #e3b8af;
  box-shadow: 0 0 0 4px rgba(227, 107, 91, 0.12);
}
.article-editor.is-empty::before {
  content: attr(data-placeholder);
  color: #9b8e80;
  pointer-events: none;
}
.article-editor img {
  width: 100%;
  max-width: 100%;
  height: auto;
  border-radius: 16px;
  display: block;
  margin: 8px 0 18px;
  background: #f4eadc;
}
.article-editor.is-drop {
  outline: 2px dashed #c45b4d;
  background: #fff6f2;
}
.editor-actions { display: flex; gap: 10px; }
.editor-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 20px;
  align-items: start;
}
.publish-panel {
  position: sticky;
  top: 24px;
  display: grid;
  gap: 12px;
  padding: 22px 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.publish-panel strong { font-size: 16px; }
.publish-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}
.publish-panel .primary-btn,
.publish-panel .ghost-btn { width: 100%; }

.feishu-import {
  border: 1px solid var(--line);
  background: #fffaf4;
  border-radius: 20px;
  padding: 16px 18px;
  display: grid;
  gap: 12px;
}
.feishu-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.feishu-row input { flex: 1 1 280px; }
.feishu-hint { color: var(--muted); font-size: 13px; margin: -4px 0 0; }
.feishu-status { font-size: 13px; line-height: 1.55; min-height: 1.2em; margin: 0; }
.feishu-status.wait { color: #b5813a; }
.feishu-status.ok { color: #2f7a4b; }
.feishu-status.err { color: #c45b4d; }
.feishu-paste {
  min-height: 92px;
  border: 1px dashed #d9c8b4;
  border-radius: 14px;
  padding: 14px 16px;
  background: #fff;
  color: #2b241c;
  outline: none;
  line-height: 1.6;
}
.feishu-paste:empty::before {
  content: attr(data-placeholder);
  color: #9b8e80;
}
.feishu-paste:focus { border-color: #c45b4d; }
.paste-image-zone {
  margin: 4px 0 12px;
  padding: 14px 16px;
  border: 1px dashed #d9c8b4;
  border-radius: 14px;
  background: #fffaf4;
  display: grid;
  gap: 8px;
}
.paste-image-zone button { justify-self: start; }
.paste-image-zone .feishu-hint.need { color: #c45b4d; }
#article-content.is-drop,
.paste-image-zone.is-drop,
.article-preview.is-drop {
  outline: 2px dashed #c45b4d;
  background: #fff6f2;
}
.article-preview-wrap span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}
.article-preview {
  background: #fffaf4;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px 20px;
  min-height: 120px;
  overflow: auto;
  font-family: "Noto Sans SC", "Source Han Sans SC", sans-serif;
  color: #2b241c;
  letter-spacing: 0.35px;
  line-height: 1.95;
}
.article-preview img { width: 100%; max-width: 100%; height: auto; border-radius: 16px; display: block; }
.article-preview video { width: 100%; max-height: 420px; border-radius: 16px; background: #111; display: block; margin: 8px 0 22px; }
.article-preview p, .article-preview li { font-size: 16px; }
.article-preview h1, .article-preview h2, .article-preview h3 { font-size: 17px; }

.cover-studio {
  border: 1px solid var(--line);
  background: #fbf6ef;
  border-radius: 20px;
  padding: 18px;
  display: grid;
  gap: 16px;
}
.cover-studio-head strong { display: block; color: var(--text); }
.cover-studio-head span { color: var(--muted); font-size: 13px; }
.cover-studio-grid {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
#cover-canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 363 / 280;
  object-fit: contain;
  border-radius: 8px;
  display: block;
  box-shadow: var(--shadow);
  background: #e8d9c3;
}
.cover-controls { display: grid; gap: 12px; }
.cover-label { display: block; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.cover-swatches, .cover-scenes { display: flex; flex-wrap: wrap; gap: 10px; }
.cover-swatch {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(43, 36, 28, 0.08);
}
.cover-swatch.active { border-color: var(--coral); transform: scale(1.08); }
.cover-scene {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
}
.cover-scene.active {
  background: #2b241c;
  color: #fffaf4;
  border-color: #2b241c;
}
.cover-upload input { padding: 10px; background: #fff; }
.cover-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.cover-controls input[type="range"] { padding: 0; box-shadow: none; border: 0; background: transparent; }
.cover-controls input[type="color"] { height: 42px; padding: 4px; }
.cover-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}
.cover-check input { width: 16px; height: 16px; margin: 0; box-shadow: none; }

@media (max-width: 900px) {
  .cover-studio-grid { grid-template-columns: 1fr; }
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(23, 20, 17, 0.42);
  display: grid;
  place-items: center;
  z-index: 20;
}
.modal-card {
  width: min(560px, calc(100% - 32px));
  background: #fffaf4;
  border-radius: 24px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head button { border: 0; background: transparent; font-size: 28px; color: var(--muted); }
#modal-body { display: grid; gap: 14px; margin-top: 12px; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: #171411;
  color: #fff;
  padding: 12px 16px;
  border-radius: 14px;
  z-index: 9999;
  max-width: min(420px, calc(100vw - 48px));
  white-space: pre-wrap;
  line-height: 1.5;
}

@media (max-width: 1100px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }
  .sidebar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "brand space foot"
      "nav nav nav";
    align-items: center;
    gap: 10px;
    padding: 10px 12px 12px;
    position: sticky;
    top: 0;
    z-index: 30;
  }
  .brand { grid-area: brand; padding: 0; gap: 8px; }
  .brand div { display: none; }
  .brand-mark { width: 34px; height: 34px; margin: 0; border-radius: 11px; font-size: 14px; }
  nav {
    grid-area: nav;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    min-width: 0;
    overflow: visible;
    gap: 6px;
  }
  nav button {
    width: 100%;
    min-width: 0;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 8px 6px;
    font-size: 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
  }
  nav button.active,
  nav button:hover {
    background: #fffaf4;
    color: #2b241c;
  }
  nav button.active { box-shadow: none; }
  .sidebar-foot {
    grid-area: foot;
    margin: 0;
    padding: 0;
    justify-content: flex-end;
  }
  .sidebar-foot #admin-name { display: none; }
  .main {
    padding: 16px 14px 32px;
    overflow-x: hidden;
  }
  .topbar { margin-bottom: 14px; gap: 10px; }
  .topbar h2 { font-size: 22px; }
  .topbar p { font-size: 12px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 14px; border-radius: 18px; }
  .stat strong { font-size: 26px; margin-top: 6px; }
  .editor-shell { grid-template-columns: minmax(0, 1fr); }
  .publish-panel { position: static; }
  .table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
  }
  .table-wrap table {
    min-width: 640px;
    width: max-content;
    max-width: none;
  }
  th, td { white-space: nowrap; }
}

@media (max-width: 720px) {
  .main { padding: 14px 12px 28px; }
  .topbar { gap: 8px; }
  .topbar h2 { font-size: 20px; }
  .topbar p {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  #primary-action { padding: 10px 14px; font-size: 14px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .card { padding: 14px; border-radius: 18px; }
  .section-head {
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .category-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 8px 10px;
  }
  .category-item .sort-cell {
    grid-column: 1 / -1;
    margin-left: 0;
    justify-content: flex-start;
  }
  .filter-bar { padding: 12px; }
  .toolbar, .form-grid { align-items: stretch; }
  .toolbar label, .form-grid label { min-width: 0; flex: 1 1 100%; }
  .toolbar button { width: 100%; }
  th, td { padding: 10px 12px; font-size: 13px; }
  .login-card { padding: 28px 20px; border-radius: 22px; }
  .modal-card { width: calc(100% - 20px); padding: 18px; }
  .toast { right: 12px; left: 12px; bottom: 16px; max-width: none; }
  .feishu-row { flex-direction: column; }
  .feishu-row input { flex: 1 1 auto; }
}
