:root {
  color-scheme: light;
  font-family: "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  background: #f4f7f7;
  color: #152528;
  font-synthesis: none;
  letter-spacing: 0;
  --ink: #152528;
  --muted: #66777a;
  --line: #d7e0e0;
  --surface: #ffffff;
  --surface-alt: #edf3f2;
  --nav: #173f45;
  --nav-2: #22575e;
  --accent: #168a87;
  --accent-dark: #0f6968;
  --warm: #ef8f76;
  --danger: #b64444;
  --warning: #a66c13;
  --success: #287a51;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { min-width: 320px; background: #f4f7f7; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(360px, 1.2fr);
}

.auth-brand {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(28px, 6vw, 72px);
  color: #f3fffd;
  background: var(--nav);
}

.brand-mark { width: 72px; height: 72px; }
.brand-title { margin: 28px 0 10px; font-size: clamp(30px, 5vw, 58px); line-height: 1.08; font-weight: 700; }
.brand-subtitle { margin: 0; color: #b9d6d3; font-size: 16px; }
.auth-main { display: grid; place-items: center; padding: 28px; }
.auth-panel { width: min(420px, 100%); }
.auth-panel h2 { margin: 0 0 8px; font-size: 24px; }
.auth-panel p { margin: 0 0 24px; color: var(--muted); }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  color: #eef9f7;
  background: var(--nav);
  overflow: hidden;
}
.sidebar-head { padding: 20px 18px 14px; border-bottom: 1px solid #2b5960; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.sidebar-brand img { width: 34px; height: 34px; }
.book-switcher { padding: 12px 10px; border-bottom: 1px solid #2b5960; }
.book-button, .nav-button {
  width: 100%;
  border: 0;
  border-radius: 6px;
  color: #d8e9e7;
  background: transparent;
  text-align: left;
  padding: 10px 11px;
}
.book-button:hover, .nav-button:hover { background: #23535a; }
.book-button.active, .nav-button.active { color: #ffffff; background: var(--nav-2); }
.book-button small { display: block; color: #9ebfbc; margin-top: 3px; }
.sidebar-nav { display: grid; gap: 3px; padding: 12px 10px; }
.sidebar-spacer { flex: 1; }
.sidebar-user { padding: 14px 18px; border-top: 1px solid #2b5960; }
.sidebar-user strong, .sidebar-user small { display: block; }
.sidebar-user small { margin-top: 3px; color: #9ebfbc; }

.workspace { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 4;
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px clamp(16px, 3vw, 36px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}
.topbar h1 { margin: 0; font-size: 20px; }
.topbar-meta { color: var(--muted); font-size: 13px; }
.main { padding: 24px clamp(16px, 3vw, 36px) 56px; }
.section { max-width: 1500px; margin: 0 auto 28px; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.section-head h2 { margin: 0; font-size: 18px; }
.section-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); background: var(--surface); }
.stat { padding: 18px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat strong { display: block; font-size: 26px; }
.stat span { color: var(--muted); font-size: 13px; }

.split { display: grid; grid-template-columns: minmax(260px, 0.75fr) minmax(420px, 1.25fr); gap: 18px; align-items: start; }
.panel { border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.panel-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-head h3 { margin: 0; font-size: 15px; }
.panel-body { padding: 16px; }
.list { margin: 0; padding: 0; list-style: none; }
.list-item { display: block; width: 100%; border: 0; border-bottom: 1px solid var(--line); background: var(--surface); padding: 13px 15px; text-align: left; color: var(--ink); }
.list-item:last-child { border-bottom: 0; }
.list-item:hover, .list-item.active { background: var(--surface-alt); }
.list-item strong { display: block; }
.list-item small, .list-item p { color: var(--muted); }
.list-item p { margin: 6px 0 0; line-height: 1.55; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field { display: grid; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 650; }
.toggle-line { display: flex; align-items: center; gap: 8px; }
.toggle-line input { width: 18px; height: 18px; accent-color: var(--accent); }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid #bfcaca;
  border-radius: 5px;
  background: #ffffff;
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px #d7efed; }
.field textarea { resize: vertical; min-height: 116px; line-height: 1.7; }
.editor { min-height: 58vh !important; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.button {
  min-height: 38px;
  border: 1px solid #b7c5c4;
  border-radius: 5px;
  background: #ffffff;
  color: var(--ink);
  padding: 8px 13px;
  font-weight: 650;
}
.button:hover { border-color: var(--accent); }
.button.primary { border-color: var(--accent); background: var(--accent); color: #ffffff; }
.button.primary:hover { background: var(--accent-dark); }
.button.danger { color: var(--danger); border-color: #dda9a9; }
.button.quiet { border-color: transparent; background: transparent; color: var(--muted); }
.button:disabled { cursor: not-allowed; opacity: 0.5; }

.module-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.module-option { display: grid; grid-template-columns: 22px 1fr; gap: 8px; padding: 11px; border: 1px solid var(--line); border-radius: 5px; background: #fff; }
.module-option:has(input:checked) { border-color: var(--accent); background: #eef9f7; }
.module-option input { width: 17px; height: 17px; margin: 2px 0 0; accent-color: var(--accent); }
.module-option strong { display: block; font-size: 13px; }
.module-option small { display: block; margin-top: 3px; color: var(--muted); line-height: 1.45; }

.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 999px; font-size: 12px; background: #e6ecec; color: #46585a; }
.badge.success { background: #def1e5; color: var(--success); }
.badge.warning { background: #faecd1; color: var(--warning); }
.badge.danger { background: #f8dddd; color: var(--danger); }
.badge.accent { background: #d9efed; color: var(--accent-dark); }
.locked-flow { display: flex; flex-wrap: wrap; gap: 6px; }

.stage-list { display: grid; gap: 8px; }
.stage-row { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: start; padding: 11px 0; border-bottom: 1px solid var(--line); }
.stage-row:last-child { border-bottom: 0; }
.stage-index { width: 25px; height: 25px; display: grid; place-items: center; border-radius: 50%; background: #dfe8e7; color: #476062; font-size: 12px; }
.stage-row.done .stage-index { background: var(--accent); color: #fff; }
.stage-row.current .stage-index { background: var(--warm); color: #422019; }
.stage-row strong { display: block; font-size: 13px; }
.stage-row small { color: var(--muted); }

.json-view { margin: 0; max-height: 520px; overflow: auto; white-space: pre-wrap; word-break: break-word; font: 12px/1.6 Consolas, monospace; color: #243638; background: #f5f8f7; padding: 14px; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.notice { padding: 12px 14px; border-left: 4px solid var(--accent); background: #eaf5f4; line-height: 1.6; }
.notice.warning { border-color: var(--warning); background: #fff7e7; }
.notice.danger { border-color: var(--danger); background: #fff0f0; }

.analysis-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 14px 0; }
.analysis-item { min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: 5px; background: #f8fbfa; }
.analysis-item strong, .analysis-item small { display: block; }
.analysis-item p { margin: 7px 0; line-height: 1.6; }
.analysis-item small { margin-bottom: 9px; color: var(--muted); line-height: 1.5; }
.proposal-form { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.proposal-review { padding: 16px; border-bottom: 1px solid var(--line); }
.proposal-review:last-child { border-bottom: 0; }
.proposal-summary small { display: block; margin-top: 4px; color: var(--muted); }
.proposal-summary p { line-height: 1.65; }
.rule-release-form { margin-top: 14px; padding: 14px; background: #f5f8f7; border: 1px solid var(--line); border-radius: 5px; }
.conflict-review { padding: 16px; border-bottom: 1px solid var(--line); }
.conflict-review:last-child { border-bottom: 0; }
.conflict-meta small { display: block; margin-top: 4px; color: var(--muted); }
.conflict-meta p { margin: 7px 0 12px; color: var(--muted); }
.conflict-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.conflict-columns textarea { min-height: 190px; resize: vertical; }
.merge-form { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }

.toast-region { position: fixed; z-index: 20; right: 18px; bottom: 18px; display: grid; gap: 8px; width: min(360px, calc(100vw - 36px)); }
.toast { padding: 12px 14px; border-radius: 6px; color: #fff; background: #233638; box-shadow: 0 8px 28px rgba(18, 37, 40, 0.22); }
.toast.error { background: #8d3030; }

.mobile-only { display: none; }

@media (max-width: 920px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; width: 260px; transform: translateX(-100%); transition: transform 160ms ease; box-shadow: 12px 0 30px rgba(0,0,0,.2); }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-flex; }
  .split { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(2) { border-right: 0; }
  .stat:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 640px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-brand { min-height: 220px; padding: 28px; }
  .brand-title { font-size: 34px; }
  .form-grid, .module-grid { grid-template-columns: 1fr; }
  .main { padding: 16px 12px 44px; }
  .topbar { padding: 10px 12px; }
  .topbar h1 { font-size: 17px; }
  .stats { grid-template-columns: 1fr; }
  .stat { border-right: 0; border-bottom: 1px solid var(--line); }
  .stat:last-child { border-bottom: 0; }
  .section-head { align-items: start; flex-direction: column; }
  .actions { width: 100%; }
  .actions .button { flex: 1 1 auto; }
  .analysis-grid { grid-template-columns: 1fr; }
  .conflict-columns { grid-template-columns: 1fr; }
}
