:root {
  --ink: #1e2a24;
  --muted: #5d6a63;
  --paper: #f3eee3;
  --panel: #fffcf6;
  --line: #d9cfc0;
  --teal: #1b6758;
  --teal-dark: #0f3f36;
  --stamp: #b33a32;
  --gold: #a57a32;
  --danger: #9b2f2a;
  --shadow: 0 18px 40px rgba(30, 42, 36, 0.12);
  --office: #2b579a;
  --office-dark: #1e3f73;
  --stage: #e6e6e6;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
[hidden] { display: none !important; }
body {
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans SC", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

button, input, textarea, select { font: inherit; }

.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 16px;
  background:
    radial-gradient(circle at 12% 18%, rgba(27, 103, 88, 0.12), transparent 36%),
    radial-gradient(circle at 88% 80%, rgba(165, 122, 50, 0.12), transparent 32%),
    var(--paper);
}
.gate-card {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 42px 40px 36px;
  box-shadow: var(--shadow);
  position: relative;
}
.gate-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 7px;
  background: linear-gradient(180deg, var(--teal), var(--gold));
}
.seal {
  margin: 0 0 8px;
  letter-spacing: 0.28em;
  font-size: 12px;
  color: var(--teal);
}
.gate-card h1 {
  margin: 0 0 12px;
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-size: 42px;
  font-weight: 600;
}
.gate-lead {
  color: var(--muted);
  line-height: 1.7;
  margin: 0 0 28px;
}
.gate-card label { display: block; margin-bottom: 8px; font-size: 13px; }
.gate-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: #fff;
  margin-bottom: 16px;
}
.gate-card button,
.btn {
  border: 1px solid var(--teal-dark);
  background: var(--teal);
  color: #fff;
  padding: 10px 16px;
  cursor: pointer;
}
.btn.primary { background: var(--teal); color: #fff; border-color: var(--teal-dark); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn.full { width: 100%; }
.btn:hover { filter: brightness(1.05); }
.link {
  border: 0;
  background: none;
  color: var(--teal);
  cursor: pointer;
  padding: 0;
}
.error { color: var(--stamp); margin: 12px 0 0; }

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
  overflow: hidden;
}
.sidebar {
  background: var(--teal-dark);
  color: #e8f3ef;
  padding: 22px 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  height: 100vh;
  z-index: 5;
}
.brand-kicker {
  display: block;
  font-size: 11px;
  letter-spacing: 0.12em;
  opacity: 0.72;
}
.brand strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
  font-family: "Songti SC", "STSong", "SimSun", serif;
}
.sidebar .btn.primary {
  background: #c9a24a;
  border-color: #8d6b24;
  color: #1a1408;
}
.sidebar .btn.full { width: 100%; }
.sidebar .btn:not(.primary):not(.home-btn) {
  background: transparent;
  color: #e8f3ef;
  border-color: rgba(255,255,255,0.28);
}
.tree-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  opacity: 0.8;
  padding: 0 6px;
}
.tree-head .link { color: #d7c087; margin-left: 10px; }
.tree {
  overflow: auto;
  flex: 1;
  padding-right: 4px;
}
.tree-node { margin: 2px 0; height: auto; display: block; }
.tree-row {
  width: 100%;
  height: 34px;
  min-height: 34px;
  max-height: 34px;
  flex-shrink: 0;
  text-align: left;
  background: transparent;
  color: inherit;
  border: 0;
  padding: 0 8px;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
}
.tree-row:hover,
.tree-row.active { background: rgba(255,255,255,0.12); }
.tree-toggle {
  flex: none;
  width: 18px;
  height: 18px;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  opacity: 0.85;
  padding: 0;
  font-size: 12px;
  line-height: 18px;
}
.tree-toggle.leaf { visibility: hidden; pointer-events: none; }
.tree-icon { flex: none; font-size: 14px; line-height: 1; width: 18px; text-align: center; }
.tree-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  line-height: 34px;
}
.tree .count {
  flex: none;
  opacity: 0.65;
  font-size: 11px;
}
.tree-children {
  padding-left: 12px;
  margin-left: 10px;
  border-left: 1px solid rgba(255,255,255,0.1);
}
.tree-file {
  width: 100%;
  height: 30px;
  text-align: left;
  background: transparent;
  color: inherit;
  border: 0;
  padding: 0 8px 0 22px;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  gap: 6px;
  align-items: center;
  opacity: 0.92;
}
.tree-file > span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tree-file:hover { background: rgba(255,255,255,0.08); }
.tree-file.active {
  background: #c9a24a;
  color: #1a1408;
  font-weight: 600;
}
.tree-file span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  line-height: 1.4;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  overflow: hidden;
}
.browse-pane {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  align-items: flex-start;
}
.topbar h2 { margin: 0; font-size: 22px; }
.muted { color: var(--muted); margin: 6px 0 0; font-size: 13px; line-height: 1.6; }
.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.top-actions input[type="search"] {
  width: 220px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  background: #fff;
}
.sidebar-toggle { display: none; }

.dropzone {
  padding: 18px 28px 40px;
  min-height: 0;
  flex: 1;
  overflow: auto;
}
.dropzone.over {
  outline: 2px dashed var(--teal);
  outline-offset: -8px;
  background: rgba(27,103,88,0.04);
}
.file-toolbar {
  margin-bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.dashboard { margin-bottom: 22px; }
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 16px 18px;
}
.kpi .label { font-size: 13px; color: var(--muted); }
.kpi .num {
  font-size: 36px;
  line-height: 1.1;
  margin: 6px 0 4px;
  font-family: "Songti SC", "STSong", "SimSun", serif;
  color: var(--teal-dark);
}
.kpi .hint { font-size: 12px; color: var(--muted); }
.dash-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 12px;
}
.dash-card {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 16px 18px;
}
.dash-card h3 { margin: 0 0 12px; font-size: 16px; }
.bar-row {
  display: grid;
  grid-template-columns: 92px 1fr 36px;
  gap: 8px;
  align-items: center;
  margin: 6px 0;
  font-size: 13px;
}
.bar {
  height: 8px;
  background: #ece4d4;
  border-radius: 99px;
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  background: var(--teal);
}
.people-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.people-table th, .people-table td {
  text-align: left;
  padding: 7px 6px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.people-table th { color: var(--muted); font-weight: 600; }
.badge {
  display: inline-block;
  font-size: 11px;
  padding: 1px 6px;
  border: 1px solid var(--line);
  margin-right: 4px;
  background: #fff;
}
.stamp-badge { color: var(--stamp); border-color: #e4b3af; }

.file-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.file-card,
.file-list .empty,
.dashboard .empty {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 14px 14px 12px;
}
.file-card {
  cursor: pointer;
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 12px;
  align-items: start;
}
.file-card:hover,
.file-card.active { border-color: var(--teal); }
.file-card.active { box-shadow: inset 0 0 0 1px var(--teal); }
.kind {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.04em;
}
.kind.word { background: var(--office); }
.kind.pdf { background: var(--stamp); }
.kind.image { background: var(--gold); }
.kind.ppt { background: #c45c26; }
.kind.excel { background: #2f6f3e; }
.kind.text { background: #44525c; }
.kind.other { background: #6b6258; }
.file-card h3 {
  margin: 0 0 4px;
  font-size: 15px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.file-card p { margin: 0; color: var(--muted); font-size: 12px; }
.file-menu {
  border: 0;
  background: none;
  cursor: pointer;
  color: var(--muted);
  padding: 2px 6px;
}
.file-list .empty,
.dashboard .empty {
  grid-column: 1 / -1;
  padding: 48px 20px;
  text-align: center;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 24, 0.45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}
.modal-card {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 24px;
  box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 16px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #fff;
}
.field textarea { min-height: 90px; resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.office {
  position: relative;
  inset: auto;
  z-index: 1;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
}
.office-titlebar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--office);
  color: #fff;
}
.office-doc-icon {
  width: 32px;
  height: 32px;
  background: #fff;
  color: var(--office);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 14px;
}
.office-title-text { flex: 1; min-width: 0; }
.office-title-text h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.office-title-text p { margin: 2px 0 0; font-size: 11px; opacity: 0.82; }
.office-title-actions { display: flex; gap: 8px; }
.office-title-actions .btn {
  background: #fff;
  color: var(--office-dark);
  border-color: #fff;
  padding: 6px 12px;
}
.office-title-actions .btn.ghost {
  background: transparent;
  color: #fff;
  border-color: rgba(255,255,255,0.45);
}
.office-title-actions .btn.saved {
  background: #1b7a4a;
  color: #fff;
  border-color: #145c38;
}
.save-banner {
  text-align: center;
  padding: 11px 16px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: #1b7a4a;
  color: #fff;
}
.save-banner.saving { background: #2b579a; }
.save-banner.error { background: #9b2f2a; }
.office-tabs {
  display: flex;
  gap: 0;
  background: #f3f3f3;
  border-bottom: 1px solid #d0d0d0;
  padding: 0 8px;
}
.office-tab {
  border: 0;
  background: transparent;
  padding: 8px 16px;
  cursor: pointer;
  color: #333;
  border-bottom: 3px solid transparent;
}
.office-tab.active {
  background: #fff;
  border-bottom-color: var(--office);
  color: var(--office);
  font-weight: 600;
}
.office-ribbon {
  display: flex;
  gap: 12px;
  padding: 8px 12px;
  background: #fff;
  border-bottom: 1px solid #d0d0d0;
  align-items: stretch;
  flex-wrap: wrap;
}
.ribbon-group {
  border-right: 1px solid #e5e5e5;
  padding-right: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  max-width: 100%;
}
.ribbon-group.grow { border-right: 0; flex: 1; }
.ribbon-cap {
  width: 100%;
  font-size: 11px;
  color: #777;
}
.ribbon-btn {
  border: 1px solid #d0d0d0;
  background: #fafafa;
  padding: 7px 12px;
  cursor: pointer;
}
.ribbon-btn.active { border-color: var(--office); color: var(--office); background: #eef3fb; }
.ribbon-select {
  padding: 6px 8px;
  border: 1px solid #d0d0d0;
  background: #fff;
  min-width: 110px;
}
.ribbon-note {
  margin: 0;
  font-size: 12px;
  color: #555;
  line-height: 1.5;
  max-width: 720px;
}
.fill-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  width: 100%;
}
.fill-fields label { font-size: 12px; color: #555; display: block; }
.fill-fields input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #d0d0d0;
}
.fill-replace {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
  margin-top: 4px;
}
.fill-replace input {
  flex: 1;
  min-width: 180px;
  padding: 8px 10px;
  border: 1px solid #d0d0d0;
}
.office-stage {
  flex: 1;
  overflow: auto;
  background: var(--stage);
}
.office-stage iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}
.office-page {
  min-height: 100%;
  padding: 24px 0 48px;
}
.docx-wrap {
  margin: 0 auto;
  transform-origin: top center;
  background: transparent;
}
.docx-wrap,
.docx-wrap * {
  box-sizing: content-box !important;
}
.office-status {
  display: flex;
  justify-content: space-between;
  padding: 4px 12px;
  font-size: 12px;
  background: #f3f3f3;
  border-top: 1px solid #d0d0d0;
  color: #555;
}
.img-view {
  display: block;
  margin: 24px auto;
  max-width: 96%;
  max-height: calc(100vh - 180px);
  background: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
}
.notice {
  max-width: 640px;
  margin: 40px auto;
  background: #fff;
  padding: 28px;
  border: 1px solid #d0d0d0;
}
.paper-edit {
  max-width: 860px;
  margin: 24px auto;
  background: #fff;
  padding: 40px 48px;
  min-height: 70vh;
  line-height: 1.8;
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
  font-family: SimSun, "Songti SC", "STSong", "宋体", serif;
  font-size: 16pt;
}
.paper-edit:focus { outline: 2px solid rgba(43,87,154,0.35); }

@media (max-width: 980px) {
  .dash-grid { grid-template-columns: 1fr; }
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px); z-index: 15; }
  .sidebar.open { display: flex; }
  .sidebar-toggle { display: inline-flex; }
}
