:root {
  --gold: #c39c6a;
  --gold-dark: #a8814f;
  --brown: #2b2118;
  --bg: #faf7f2;
  --white: #ffffff;
  --ink: #342d27;
  --muted: #746d66;
  --line: #e9e2d8;
  --danger: #b5483d;
  --success: #3f7a58;
  --shadow: 0 12px 35px rgba(43, 33, 24, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; color: var(--ink); background: var(--bg); font-family: var(--font); }
body { margin: 0; min-height: 100vh; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.48; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.is-hidden { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: auto minmax(280px, 1fr) auto;
  gap: 24px;
  align-items: center;
  min-height: 76px;
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.98);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 10px; align-items: center; color: var(--brown); text-decoration: none; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; color: var(--white); background: var(--brown); border-radius: 8px; font: 700 11px/1 Georgia, serif; letter-spacing: 0.12em; }
.brand strong, .brand small { display: block; }
.brand strong { font-family: Georgia, "Songti SC", serif; font-size: 18px; letter-spacing: 0.08em; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.data-meta { display: flex; gap: 14px; align-items: center; min-width: 0; color: var(--muted); font-size: 12px; }
.data-meta > span { white-space: nowrap; }
.data-meta strong { color: var(--ink); font-weight: 600; }
.source-status { display: inline-flex; gap: 6px; align-items: center; padding: 6px 9px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); color: var(--ink); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #a8a19a; }
.source-status--online .status-dot { background: var(--success); box-shadow: 0 0 0 3px rgba(63, 122, 88, 0.12); }
.source-status--conflict .status-dot { background: var(--danger); box-shadow: 0 0 0 3px rgba(181, 72, 61, 0.12); }
.top-actions { display: flex; gap: 8px; align-items: center; }
.actor-field { display: grid; gap: 2px; color: var(--muted); font-size: 10px; }
.actor-field input { width: 112px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: var(--white); }
.dirty-pill { padding: 8px 10px; border-radius: 999px; color: var(--gold-dark); background: #f6eddf; white-space: nowrap; font-size: 12px; }
.dirty-pill.is-clean { color: var(--muted); background: #f2f0ed; }

.btn { display: inline-flex; gap: 6px; align-items: center; justify-content: center; min-height: 36px; padding: 8px 13px; border: 1px solid transparent; border-radius: 7px; font-weight: 600; font-size: 13px; transition: border-color .18s ease, background .18s ease; }
.btn--primary { color: var(--white); background: var(--gold); }
.btn--primary:hover:not(:disabled) { background: var(--gold-dark); }
.btn--secondary { color: var(--ink); background: var(--white); border-color: var(--line); }
.btn--secondary:hover:not(:disabled) { border-color: var(--gold); }
.btn--text { min-height: auto; padding: 5px; color: var(--gold-dark); background: transparent; }
.btn--danger { color: var(--white); background: var(--danger); }
.btn small, .btn strong { display: block; }
.icon-button { display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%; color: var(--muted); background: transparent; font-size: 26px; }
.icon-button:hover { background: var(--bg); color: var(--ink); }

.app-shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 76px); }
.sidebar { position: sticky; top: 76px; align-self: start; display: flex; flex-direction: column; justify-content: space-between; height: calc(100vh - 76px); padding: 24px 14px; background: var(--white); border-right: 1px solid var(--line); }
.nav-title { margin: 0 10px 10px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .12em; }
.nav-title--later { margin-top: 28px; }
.nav-item { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; width: 100%; margin: 2px 0; padding: 11px 12px; border: 0; border-radius: 8px; color: var(--ink); background: transparent; text-align: left; }
.nav-item:hover:not(:disabled) { background: var(--bg); }
.nav-item.is-active { color: var(--brown); background: #f6eddf; box-shadow: inset 3px 0 var(--gold); }
.nav-item b { min-width: 25px; padding: 2px 6px; border-radius: 999px; background: rgba(195, 156, 106, .14); text-align: center; font-size: 11px; }
.nav-item small { color: var(--muted); font-size: 10px; }
.nav-item.is-disabled { color: #aaa39d; }
.sidebar-note { padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.sidebar-note strong { color: var(--brown); font-size: 12px; }
.sidebar-note p { margin: 7px 0 0; color: var(--muted); font-size: 11px; line-height: 1.6; }

.main-content { min-width: 0; padding: 34px; }
.content-header { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; max-width: 1440px; margin: 0 auto 24px; }
.content-header h1 { margin: 4px 0 8px; color: var(--brown); font: 600 30px/1.2 Georgia, "Songti SC", serif; }
.content-header p:last-child { max-width: 720px; margin: 0; color: var(--muted); font-size: 14px; line-height: 1.7; }
.eyebrow { margin: 0; color: var(--gold-dark); font-size: 11px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; }
.readonly-badge { padding: 6px 10px; border-radius: 999px; color: var(--muted); background: #f0eeeb; font-size: 12px; }
.panel { max-width: 1440px; margin: 0 auto; overflow: hidden; background: var(--white); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.toolbar { display: flex; gap: 10px; align-items: center; padding: 16px; border-bottom: 1px solid var(--line); }
.toolbar input, .toolbar select { min-height: 38px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); background: var(--white); }
.search-field { flex: 1; }
.search-field input { width: 100%; max-width: 420px; }
.list-count { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 13px 15px; border-bottom: 1px solid #f0ebe4; text-align: left; font-size: 13px; }
th { position: sticky; top: 0; z-index: 1; color: var(--muted); background: #fcfaf7; font-size: 11px; font-weight: 700; letter-spacing: .04em; }
tbody tr:hover { background: #fdfbf8; }
.table-action { text-align: right; }
.empty-state, .loading-state, .fatal-state { display: grid; place-items: center; min-height: 220px; padding: 32px; color: var(--muted); text-align: center; }
.loading-state { min-height: calc(100vh - 160px); align-content: center; }
.spinner { width: 28px; height: 28px; border: 2px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal { width: min(820px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 0; border-radius: 12px; color: var(--ink); background: var(--white); box-shadow: 0 30px 80px rgba(43, 33, 24, .24); }
.modal::backdrop { background: rgba(43, 33, 24, .36); backdrop-filter: blur(2px); }
.modal--small { width: min(560px, calc(100vw - 32px)); }
.modal form { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.modal-header { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; padding: 22px 24px 16px; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 5px 0 0; color: var(--brown); font-size: 22px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; padding: 22px 24px; overflow-y: auto; }
.form-field { display: grid; gap: 7px; align-content: start; }
.form-field:has(textarea) { grid-column: 1 / -1; }
.form-field label { color: var(--ink); font-size: 12px; font-weight: 700; }
.form-field label em { margin-left: 3px; color: var(--danger); font-style: normal; }
.form-field input, .form-field textarea, .form-field select { width: 100%; padding: 10px 11px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); background: var(--white); outline: none; }
.form-field textarea { resize: vertical; line-height: 1.6; }
.form-field input:focus, .form-field textarea:focus, .form-field select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(195, 156, 106, .12); }
.form-field input:disabled, .form-field textarea:disabled, .form-field select:disabled { color: var(--muted); background: #f5f3ef; }
.form-field small { color: var(--muted); font-size: 11px; }
.field-error { min-height: 14px; margin: 0; color: var(--danger); font-size: 11px; }
.form-field.has-error input, .form-field.has-error textarea, .form-field.has-error select { border-color: var(--danger); background: #fff9f8; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 24px; border-top: 1px solid var(--line); }
.conflict-content > p { margin: 20px 24px; color: var(--muted); line-height: 1.7; }
.conflict-actions { display: grid; gap: 10px; padding: 0 24px 24px; }
.conflict-actions .btn { display: block; min-height: 60px; text-align: left; }
.conflict-actions small { margin-top: 4px; font-weight: 400; opacity: .82; }

.drawer-backdrop { position: fixed; inset: 0; z-index: 39; visibility: hidden; background: rgba(43, 33, 24, .25); opacity: 0; transition: opacity .2s, visibility .2s; }
.drawer-backdrop.is-open { visibility: visible; opacity: 1; }
.snapshot-drawer { position: fixed; top: 0; right: 0; z-index: 40; width: min(440px, 100vw); height: 100vh; padding: 24px; overflow-y: auto; background: var(--white); box-shadow: -20px 0 60px rgba(43, 33, 24, .16); transform: translateX(102%); transition: transform .25s ease; }
.snapshot-drawer.is-open { transform: translateX(0); }
.snapshot-drawer > header { display: flex; justify-content: space-between; align-items: flex-start; }
.snapshot-drawer h2 { margin: 5px 0 0; color: var(--brown); }
.snapshot-drawer h3 { margin-top: 28px; color: var(--brown); font-size: 14px; }
.drawer-tip { padding: 12px; color: var(--muted); background: var(--bg); border-left: 3px solid var(--gold); font-size: 12px; line-height: 1.6; }
.drawer-loading { padding: 30px 0; color: var(--muted); text-align: center; }
.snapshot-card { margin-top: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; }
.snapshot-card > div:first-child { display: flex; justify-content: space-between; gap: 10px; }
.snapshot-card strong { color: var(--gold-dark); }
.snapshot-card span, .snapshot-card p { color: var(--muted); font-size: 12px; }
.snapshot-card p { margin: 8px 0; }
.snapshot-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.snapshot-drawer pre { min-height: 130px; padding: 12px; overflow: auto; border-radius: 7px; color: var(--ink); background: var(--bg); font-size: 11px; white-space: pre-wrap; }
.error-box { margin-top: 16px; padding: 14px; color: var(--danger); background: #fff4f2; border-radius: 7px; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 80; max-width: min(430px, calc(100vw - 32px)); padding: 12px 16px; color: var(--white); background: var(--brown); border-radius: 8px; box-shadow: var(--shadow); opacity: 0; transform: translateY(16px); pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast--success { background: var(--success); }
.toast--error { background: var(--danger); }
.toast--warn { background: #8a6d3b; }

@media (max-width: 1180px) {
  .topbar { grid-template-columns: auto 1fr; }
  .data-meta { display: none; }
  .top-actions { grid-column: 1 / -1; overflow-x: auto; padding-bottom: 2px; }
  .app-shell { min-height: calc(100vh - 126px); }
  .sidebar { top: 126px; height: calc(100vh - 126px); }
}

@media (max-width: 760px) {
  .topbar { position: static; display: flex; flex-direction: column; align-items: stretch; padding: 12px 16px; }
  .top-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; }
  .actor-field, .dirty-pill { grid-column: 1 / -1; }
  .actor-field input { width: 100%; }
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 10px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar nav { display: flex; min-width: max-content; }
  .nav-title, .nav-title--later, .sidebar-note, .nav-item small { display: none; }
  .nav-item { width: auto; grid-template-columns: auto auto; }
  .main-content { padding: 22px 14px; }
  .content-header { display: block; }
  .readonly-badge { display: inline-block; margin-top: 12px; }
  .toolbar { flex-wrap: wrap; }
  .search-field { flex-basis: 100%; }
  .search-field input { max-width: none; }
  .list-count { width: 100%; margin-left: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .form-field:has(textarea) { grid-column: auto; }
}
