:root {
  --ink: #241910;
  --muted: #7a6550;
  --red: #9d2b2b;
  --gold: #b08948;
  --paper: #f6efe2;
  --sheet: #fffaf1;
  --panel: #fbf6ec;
  --line: rgba(36, 25, 16, 0.12);
  --shadow: 0 18px 50px rgba(48, 28, 12, 0.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(157, 43, 43, 0.08), transparent 32%),
    linear-gradient(180deg, #efe4d2 0%, #e7d8c0 100%);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
}

.app { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 241, 0.86);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.nav { display: flex; gap: 6px; flex-wrap: wrap; }
.nav-btn.active {
  background: var(--ink);
  color: #fff8f0;
  border-color: var(--ink);
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: 0.08em; font-weight: 700; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.brand .project-line { color: var(--ink); font-size: 14px; font-weight: 600; }

.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
}
button.small { padding: 6px 12px; font-size: 13px; margin-top: 8px; }
button.ghost { background: transparent; }
button.primary {
  background: var(--red);
  color: #fff8f0;
  border-color: var(--red);
}
button.primary:disabled {
  background: #cbb8a6;
  border-color: #cbb8a6;
  cursor: not-allowed;
}
button:hover:not(:disabled) { filter: brightness(0.97); }

.workspace {
  display: grid;
  grid-template-columns: minmax(420px, 46%) 1fr;
  gap: 22px;
  padding: 22px 28px 40px;
  align-items: start;
}

.form-pane, .paper {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.form-pane {
  padding: 8px 22px 28px;
  border-radius: 18px;
}

section { padding: 18px 0; border-bottom: 1px dashed var(--line); }
section:last-child { border-bottom: 0; }
h2 {
  margin: 0 0 14px;
  font-size: 15px;
  letter-spacing: 0.18em;
  color: var(--red);
}
h3 { margin: 16px 0 10px; font-size: 13px; color: var(--muted); font-weight: 600; }

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}
select,
input, textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  resize: vertical;
}
input:focus, textarea:focus { outline: 2px solid rgba(157, 43, 43, 0.25); border-color: var(--red); }

.grid-2, .grid-3 { display: grid; gap: 10px 12px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.hint, .money-line { color: var(--muted); font-size: 12px; margin: 0 0 12px; }
.money-line { color: var(--red); font-size: 14px; }
.req { color: var(--red); }
.hidden { display: none; }

.mode-switch { display: flex; gap: 16px; margin-bottom: 12px; }
.radio { display: flex; align-items: center; gap: 6px; color: var(--ink); font-size: 13px; margin: 0; }
.radio input { width: auto; margin: 0; }

.item-row, .period-row {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
  align-items: end;
}
.item-row { grid-template-columns: 40px 1fr auto; }
.item-row.priced { grid-template-columns: 40px 1fr 72px 88px 88px auto; }
.period-row { grid-template-columns: 52px 90px 1fr 120px auto auto; }
.item-row .idx, .period-row .idx {
  font-size: 12px;
  color: var(--muted);
  padding-bottom: 10px;
}
.check { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.check input { width: auto; margin: 0; }

.preview-pane { position: sticky; top: 96px; }
.preview-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.preview-toolbar .hint { margin: 0; flex: 1; min-width: 180px; }
.preview-toolbar .small { margin-top: 0; }
.paper [contenteditable="true"] { outline: none; border-radius: 2px; }
.paper [contenteditable="true"]:focus { outline: 1px dashed rgba(157, 43, 43, 0.45); background: rgba(157, 43, 43, 0.04); }
.paper .block { min-height: 1.6em; }
.paper .scope-act { width: 52px; border: 0; }
.paper .scope-act button { margin: 0; padding: 2px 8px; }
.edit-dirty { color: var(--red); }
.paper {
  min-height: 78vh;
  padding: 42px 48px 56px;
  background: var(--sheet);
  border-radius: 4px;
  font-family: "STSong", "SimSun", "Songti SC", serif;
  line-height: 1.85;
}
.paper h1 {
  text-align: center;
  font-size: 26px;
  letter-spacing: 0.12em;
  margin: 0 0 28px;
}
.paper h4 { margin: 18px 0 6px; font-size: 16px; }
.paper p { margin: 0 0 8px; text-indent: 2em; }
.paper .indent-0 { text-indent: 0; }
.paper .kv { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 24px; text-indent: 0; }
.paper .u { text-decoration: underline; text-underline-offset: 3px; }
.paper table { width: 100%; border-collapse: collapse; margin: 8px 0 16px; font-size: 14px; }
.paper td, .paper th { border: 1px solid #6b4f3a; padding: 6px 8px; }
.paper-placeholder { color: var(--muted); text-indent: 0; text-align: center; margin-top: 24vh; }

.alerts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.alert {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
}
.alert.error { background: #f8d7d3; color: #7a1b1b; }
.alert.warn { background: #f4e3c1; color: #6b4a12; }

.suggest-wrap { position: relative; }
.suggest {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 8;
  overflow: hidden;
}
.suggest button {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 0;
  text-align: left;
  padding: 8px 12px;
}
.suggest button:hover { background: #f4e8d6; }

.list-view { padding: 22px 28px 40px; }
.list-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.list-toolbar input { width: auto; min-width: 180px; margin: 0; }
.data-table { width: 100%; border-collapse: collapse; background: var(--panel); box-shadow: var(--shadow); }
.data-table th, .data-table td { border-bottom: 1px solid var(--line); padding: 10px 12px; text-align: left; font-size: 14px; }
.data-table th { color: var(--muted); font-weight: 600; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.row-actions .small { margin-top: 0; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 14px;
  padding: 16px 18px;
  margin-bottom: 12px;
}
.card h3 { margin: 0 0 8px; color: var(--ink); }
.card p { margin: 4px 0; color: var(--muted); font-size: 13px; }
.tag { font-size: 12px; color: var(--red); margin-left: 8px; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(36, 25, 16, 0.42);
}
.modal.hidden { display: none; }
.modal-card {
  width: min(640px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 20px 22px 18px;
}
.modal-card h2 { margin: 0 0 14px; color: var(--ink); font-size: 18px; }
.modal-card label { margin-bottom: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.app.locked { filter: blur(2px); pointer-events: none; user-select: none; }
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(36, 25, 16, 0.48);
}
.auth-gate.hidden { display: none; }
.auth-gate .modal-card { width: min(420px, 100%); }
.settings-pane { max-width: 480px; box-shadow: none; padding: 0; }
#auth-error, #settings-msg { color: var(--red); min-height: 1.2em; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; }
  .preview-pane { position: static; }
  .period-row { grid-template-columns: 1fr 1fr; }
}
