:root {
  color-scheme: light;
  --bg: #eef3f8;
  --surface: #f8fbfe;
  --surface-strong: #ffffff;
  --surface-muted: #eaf2ff;
  --ink: #102033;
  --muted: #5f7187;
  --muted-dark: #496b8d;
  --line: #cfe1f2;
  --line-strong: #a9c8e5;
  --accent: #1687c7;
  --accent-soft: #e6f4ff;
  --accent-dark: #0d2b4c;
  --coral: #d5544a;
  --danger: #d5544a;
  --shadow: 0 10px 24px rgba(30, 86, 138, .08);
  --sidebar-width: 240px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", Arial, sans-serif;
  letter-spacing: 0;
}
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent-dark);
  outline-offset: 2px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.hidden { display: none !important; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  background: #06233c;
  border-right: 1px solid #123d61;
  transition: transform .2s ease;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 98px;
  padding: 0 16px;
  border-bottom: 1px solid #123d61;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  border-radius: 4px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
  font-size: 17px;
}
.brand strong { display: block; font-size: 16px; }
.brand span { display: block; margin-top: 4px; color: var(--muted-dark); font-size: 10px; }
.side-nav { flex: 1; padding: 22px 8px 12px; overflow: auto; }
.nav-label {
  padding: 0 12px;
  margin: 0 0 8px;
  color: #8aa2b6;
  font-size: 11px;
}
.nav-label:not(:first-child) { margin-top: 22px; }
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 38px;
  padding: 0 12px;
  margin: 2px 0;
  border-radius: 10px;
  color: #d7e8f8;
  font-size: 13px;
  text-decoration: none;
}
.nav-item:hover { background: rgba(48, 132, 216, .2); }
.nav-item.active {
  background: var(--accent-soft);
  color: #0d2b4c;
}
.nav-item.active::before {
  position: absolute;
  left: 0;
  top: 10px;
  width: 3px;
  height: 18px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  content: "";
}
.nav-icon { width: 17px; text-align: center; color: #9fc9ef; font-size: 17px; line-height: 1; }
.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  border-top: 1px solid #123d61;
  color: #9fc0dd;
  font-size: 11px;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #58a56f; }

.main-area { flex: 1; min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 22px;
  height: 98px;
  padding: 0 26px 0 30px;
  background: rgba(238, 243, 248, .94);
  border-bottom: 1px solid #cfe1f2;
  backdrop-filter: blur(10px);
}
.topbar-left { display: flex; align-items: center; gap: 20px; min-width: 0; }
.icon-button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #496b8d;
  font-size: 19px;
}
.icon-button:hover { color: var(--ink); }
.breadcrumbs { display: flex; align-items: center; gap: 10px; white-space: nowrap; font-size: 14px; }
.breadcrumbs span { color: var(--muted); }
.breadcrumbs b { color: #8aa2b6; font-weight: 400; }
.breadcrumbs strong { font-weight: 700; }
.global-search {
  display: flex;
  align-items: center;
  width: min(420px, 38vw);
  height: 38px;
  padding: 0 8px 0 12px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .86);
  color: var(--muted);
}
.global-search:focus-within { border-color: var(--accent); background: var(--surface-strong); }
.search-symbol { margin-right: 8px; font-size: 22px; line-height: 1; transform: rotate(-20deg); }
.global-search input { min-width: 0; flex: 1; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 12px; }
.global-search kbd {
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 10px;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.date-badge {
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .78);
  color: var(--ink);
  font-size: 12px;
  white-space: nowrap;
}
.date-badge em { margin-left: 7px; color: var(--muted); font-style: normal; }

.content { max-width: 1440px; padding: 27px 34px 52px; margin: 0 auto; }
.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin: 0 0 27px;
}
.section-kicker { margin: 0 0 5px; color: var(--muted-dark); font-size: 11px; }
h1, h2, p { margin: 0; }
h1 { font-size: 28px; line-height: 1.2; }
.page-subtitle { margin-top: 6px; color: var(--muted); font-size: 13px; }
.primary-button, .secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 37px;
  padding: 0 14px;
  border-radius: 10px;
  font-size: 13px;
  white-space: nowrap;
}
.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
}
.primary-button:hover { background: #0d6fa9; }
.primary-button span { font-size: 18px; line-height: 1; }
.secondary-button { border: 1px solid var(--line); background: var(--surface-strong); color: var(--ink); }
.secondary-button:hover { border-color: var(--line-strong); background: #f8fcff; }
.text-button { border: 0; background: transparent; color: var(--muted); font-size: 13px; }
.text-button:hover { color: var(--ink); }
.text-button.danger { color: var(--danger); }

.workspace-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.toolbar-search {
  display: flex;
  align-items: center;
  width: 240px;
  height: 37px;
  padding: 0 9px 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .86);
}
.toolbar-search:focus-within { border-color: var(--accent); background: #ffffff; }
.toolbar-search > span { margin-right: 8px; color: var(--muted); font-size: 20px; transform: rotate(-20deg); }
.toolbar-search input { min-width: 0; flex: 1; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 12px; }
.clear-button { border: 0; background: transparent; color: #8aa2b6; font-size: 18px; }
.clear-button:hover { color: var(--ink); }
.select-wrap { position: relative; }
.select-wrap::after {
  position: absolute;
  right: 13px;
  top: 12px;
  color: var(--muted);
  content: "⌄";
  pointer-events: none;
}
select {
  width: 106px;
  height: 37px;
  padding: 0 32px 0 13px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  outline: 0;
  appearance: none;
  background: var(--surface-strong);
  color: var(--ink);
  font-size: 12px;
}
.editor-modal select {
  width: 100%;
  height: 41px;
  padding: 0 34px 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  color: var(--ink);
  font-size: 13px;
}
.editor-modal select:focus { border-color: var(--accent); }
.toolbar-spacer { flex: 1; }
.result-count { color: var(--muted); font-size: 12px; }
.view-switch { display: flex; gap: 2px; margin-left: 10px; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: #e6edf5; }
.view-button { width: 29px; height: 27px; padding: 0; border: 0; border-radius: 5px; background: transparent; color: var(--muted); }
.view-button.active { background: var(--surface-strong); color: var(--ink); box-shadow: 0 1px 3px rgba(30, 86, 138, .1); }

.template-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.template-card {
  min-width: 0;
  min-height: 182px;
  padding: 17px 16px 14px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255, 255, 255, .92);
  cursor: pointer;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.template-card:hover { border-color: var(--line-strong); background: var(--surface-strong); box-shadow: var(--shadow); transform: translateY(-2px); }
.template-grid.list-view { grid-template-columns: 1fr; gap: 8px; }
.template-grid.list-view .template-card {
  display: grid;
  grid-template-columns: minmax(110px, .25fr) minmax(180px, .55fr) minmax(220px, 1.6fr) auto;
  grid-template-rows: auto auto;
  align-items: center;
  min-height: 0;
  padding: 12px 16px;
}
.template-grid.list-view .card-topline { grid-column: 1; grid-row: 1 / span 2; }
.template-grid.list-view .card-topline .card-pin { margin-left: 7px; }
.template-grid.list-view .template-card h2 { grid-column: 2; grid-row: 1 / span 2; margin: 0; }
.template-grid.list-view .card-preview { grid-column: 3; grid-row: 1; min-height: 0; margin: 0; }
.template-grid.list-view .card-tags { grid-column: 3; grid-row: 2; margin: 5px 0 0; }
.template-grid.list-view .card-bottom { grid-column: 4; grid-row: 1 / span 2; margin: 0; flex-direction: column; align-items: flex-end; gap: 4px; }
.card-topline { display: flex; align-items: center; justify-content: space-between; min-height: 17px; }
.card-actions { display: inline-flex; align-items: center; gap: 5px; }
.card-category { color: var(--muted-dark); font-size: 11px; }
.card-pin { color: var(--coral); font-size: 15px; }
.card-delete {
  display: grid;
  place-items: center;
  width: 23px;
  height: 23px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #8aa2b6;
  font-size: 17px;
  line-height: 1;
  opacity: .78;
}
.card-delete:hover { background: #fff0ee; color: var(--danger); opacity: 1; }
.card-delete:focus-visible { outline: 2px solid var(--danger); outline-offset: 1px; }
.template-card h2 { margin-top: 12px; font-size: 15px; line-height: 1.35; }
.card-preview {
  display: -webkit-box;
  min-height: 49px;
  margin-top: 10px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}
.card-bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 13px; color: var(--muted); font-size: 11px; }
.card-bottom span:last-child { white-space: nowrap; }
.card-tags { display: flex; gap: 5px; min-width: 0; margin-top: 10px; overflow: hidden; }
.tag {
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted-dark);
  font-size: 10px;
  white-space: nowrap;
}
.empty-state { padding: 80px 20px; text-align: center; color: var(--muted); }
.empty-icon { color: #8aa2b6; font-size: 42px; transform: rotate(-20deg); }
.empty-state h2 { margin-top: 14px; color: var(--ink); font-size: 17px; }
.empty-state p { margin: 8px 0 18px; font-size: 13px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(16, 32, 51, .35);
}
.modal {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-strong);
  box-shadow: 0 22px 60px rgba(30, 86, 138, .18);
}
.modal-close {
  position: absolute;
  right: 18px;
  top: 15px;
  width: 30px;
  height: 30px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
}
.modal-close:hover { color: var(--ink); }
.modal-meta-line { display: flex; align-items: center; gap: 10px; }
.category-pill { color: var(--muted-dark); font-size: 12px; }
.pin-label { color: var(--coral); font-size: 11px; }
.detail-modal h2, .editor-modal h2 { margin-top: 9px; padding-right: 28px; font-size: 21px; line-height: 1.4; }
.detail-updated { margin-top: 7px; color: var(--muted); font-size: 11px; }
.detail-content {
  min-height: 180px;
  margin-top: 20px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfdff;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.8;
  white-space: pre-wrap;
}
.detail-content img,
.rich-editor img {
  display: inline-block;
  max-width: min(100%, 260px);
  max-height: 180px;
  margin: 2px 4px;
  border-radius: 6px;
  vertical-align: middle;
  object-fit: contain;
}
.detail-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 13px; }
.modal-actions { display: flex; align-items: center; gap: 9px; margin-top: 22px; }
.editor-modal h2 { margin-bottom: 21px; }
.editor-modal form { display: grid; gap: 15px; }
.form-grid { display: grid; grid-template-columns: 1.4fr .9fr; gap: 13px; }
label { display: grid; gap: 7px; color: var(--muted-dark); font-size: 12px; }
label small { color: #8aa2b6; font-size: 10px; }
label input, label textarea, .rich-editor {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  resize: vertical;
  background: #fbfdff;
  color: var(--ink);
  font-size: 13px;
}
.rich-editor {
  min-height: 250px;
  max-height: 420px;
  overflow: auto;
  background: #fbfdff;
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-word;
}
.rich-editor:empty::before {
  color: #8aa2b6;
  content: attr(data-placeholder);
  pointer-events: none;
}
label input:focus, label textarea:focus, .rich-editor:focus { border-color: var(--accent); }
.checkbox-row { display: flex; align-items: center; grid-template-columns: none; gap: 8px; }
.checkbox-row input { width: 15px; height: 15px; accent-color: var(--accent); }
.editor-actions { margin-top: 4px; }
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 80;
  max-width: min(360px, calc(100vw - 48px));
  padding: 11px 15px;
  border: 1px solid #0d2b4c;
  border-radius: 8px;
  background: #0d2b4c;
  color: #ffffff;
  box-shadow: 0 10px 28px rgba(30, 86, 138, .18);
  font-size: 12px;
}

body.dark {
  --bg: #091a2b;
  --surface: #102b43;
  --surface-strong: #143650;
  --surface-muted: #1a4265;
  --ink: #f2f7fc;
  --muted: #b2c7da;
  --muted-dark: #d4e8f8;
  --line: #2a5375;
  --line-strong: #4785b6;
  --accent-soft: #1a4e7b;
  --accent-dark: #d7edff;
  --coral: #ff9a8f;
  background: var(--bg);
}
body.dark .sidebar { background: #061a2d; border-color: #123d61; }
body.dark .topbar { background: rgba(9, 26, 43, .94); border-color: #2a5375; }
body.dark .template-card, body.dark .global-search, body.dark .toolbar-search, body.dark .date-badge { background: #102b43; border-color: #2a5375; }
body.dark .template-card:hover, body.dark .modal, body.dark .detail-content, body.dark label input, body.dark label textarea, body.dark .rich-editor { background: #143650; }
body.dark .view-switch { background: #102b43; border-color: #2a5375; }
body.dark .tag { background: #1a4265; }
body.dark .modal { border-color: #2a5375; }

@media (max-width: 1180px) {
  .template-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .topbar-left { min-width: 210px; }
  .global-search { width: min(350px, 34vw); }
}
@media (max-width: 880px) {
  :root { --sidebar-width: 0px; }
  .sidebar { width: 240px; transform: translateX(-100%); box-shadow: 8px 0 22px rgba(40, 34, 27, .12); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .main-area { margin-left: 0; }
  .topbar { gap: 10px; padding: 0 16px; }
  .topbar-left { min-width: 0; }
  .global-search { width: min(300px, 42vw); }
  .topbar-actions .icon-button { display: none; }
  .content { padding: 24px 18px 42px; }
  .template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .topbar { height: 76px; }
  .breadcrumbs { font-size: 12px; }
  .global-search { display: none; }
  .date-badge { margin-left: auto; font-size: 11px; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .page-heading .primary-button { align-self: flex-start; }
  .workspace-toolbar { align-items: stretch; flex-wrap: wrap; }
  .toolbar-search { flex: 1 1 220px; width: auto; }
  .toolbar-spacer { display: none; }
  .result-count { order: 4; width: 100%; }
  .view-switch { margin-left: auto; }
  .template-grid { grid-template-columns: 1fr; }
  .template-grid.list-view .template-card { display: block; }
  .template-grid.list-view .card-topline { display: flex; }
  .template-grid.list-view .template-card h2 { margin-top: 12px; }
  .template-grid.list-view .card-preview { margin-top: 10px; }
  .template-grid.list-view .card-tags { margin-top: 10px; }
  .template-grid.list-view .card-bottom { flex-direction: row; align-items: center; margin-top: 13px; }
  .form-grid { grid-template-columns: 1fr; }
  .modal { padding: 23px 18px; }
  .modal-actions { flex-wrap: wrap; }
}
