:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --line: #e5e6eb;
  --text: #1d2129;
  --muted: #86909c;
  --accent: #1668dc;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  height: 52px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .5px;
}

.nav {
  display: flex;
  align-items: center;
  font-size: 13px;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 4px 2px;
}

.nav a + a {
  border-left: 1px solid var(--line);
  margin-left: 10px;
  padding-left: 10px;
}

.nav a.active { color: var(--accent); }

/* ---------- 主区域 ---------- */
.main {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 12px 20px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 12px;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 13px;
  line-height: 1;
  padding: 9px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, border-color .15s, opacity .15s;
}

.btn:hover { border-color: #c9cdd4; }
.btn:active { background: #f2f3f5; }
.btn[disabled] { opacity: .5; cursor: default; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:active { background: #1155ba; }

.stage {
  padding: 0;
  overflow: hidden;
}

.stage-box {
  position: relative;
  margin: 0 auto;
}

.paper-scaler {
  position: absolute;
  top: 0;
  left: 0;
  width: 794px;
  transform-origin: top left;
}

/* ---------- A4 介绍信（严格还原 docx 版式） ---------- */
.paper {
  width: 794px;
  min-height: 1123px;
  padding: 96px 120px;
  background: #fff;
  color: #000;
  font-family: "SimSun", "宋体", "Songti SC", "STSong", serif;
  font-weight: 700;
  box-shadow: 0 2px 14px rgba(0, 0, 0, .1);
}

.doc-title {
  margin: 0 0 14px;
  font-size: 29.33px;
  line-height: 1.5;
  font-weight: 700;
  text-align: center;
}

.doc-line {
  margin: 0;
  font-size: 21.33px;
  line-height: 1.9;
  text-align: justify;
}

.doc-line.indent { text-indent: 2em; }

.doc-line.field {
  display: flex;
  align-items: flex-end;
}

.doc-line.field > span:first-child {
  flex: 0 0 auto;
  white-space: nowrap;
}

.doc-line.field .fill {
  flex: 1 1 auto;
  min-height: 1.25em;
  border-bottom: 1px solid #000;
  padding: 0 6px;
  line-height: 1.55;
  word-break: break-all;
  text-align: left;
}

.fill-inline {
  display: inline-block;
  min-width: 4.2em;
  border-bottom: 1px solid #000;
  line-height: 1.45;
  text-align: center;
  vertical-align: baseline;
  text-indent: 0;
}

.fill-inline.date { min-width: 3.4em; }
.fill-inline.sign-blank { min-width: 6em; }

.sign {
  margin-top: 24px;
}

.sign-line {
  margin: 0;
  font-size: 21.33px;
  line-height: 1.9;
  text-align: right;
}

.sign-line { padding-right: 1.2em; }
.sign-line.name-line { padding-right: 2.2em; }
.sign-line.date-line { padding-right: .2em; }

/* ---------- 页脚 ---------- */
.footer {
  padding: 10px 14px 14px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.modal[hidden] { display: none; }

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .45);
}

.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: 88vh;
  background: var(--card);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .16);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.modal-close {
  border: 0;
  background: none;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0 2px;
}

.modal-body {
  padding: 14px 16px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--line);
}

.foot-gap { flex: 1; }

.input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  outline: none;
}

.input:focus { border-color: var(--accent); }

.channel-list {
  margin-top: 10px;
  max-height: 46vh;
  overflow: auto;
}

.channel-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  font-family: inherit;
}

.channel-item:hover { border-color: var(--accent); }
.channel-item:active { background: #f2f7ff; }

.channel-item .short {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.channel-item .full {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}

.step-sub {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
}

.step-sub b { color: var(--text); }

.form-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.form-row > span {
  flex: 0 0 84px;
  font-size: 13px;
  color: var(--muted);
}

.tip {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

.tip.error { color: #d4380d; }
.tip a { color: var(--accent); }

.preview-img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  background: rgba(29, 33, 41, .9);
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 20px;
  z-index: 200;
  max-width: 80vw;
  text-align: center;
}

.toast[hidden] { display: none; }

.loading {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(255, 255, 255, .92);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--text);
}

.loading[hidden] { display: none; }

/* ---------- 后台 ---------- */
.login-card {
  max-width: 380px;
  margin: 6vh auto 0;
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .06);
}

.card-title {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
}

.login-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 6px;
}

.panel-head .card-title { margin: 0; }

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ch-list { margin-top: 10px; }

.ch-row {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 10px;
}

.ch-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ch-cell > span {
  font-size: 12px;
  color: var(--muted);
}

.ch-cell .input {
  padding: 7px 10px;
  font-size: 13px;
}

.ch-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.btn-danger {
  color: #d4380d;
  border-color: #ffd8c7;
}

.btn-danger:active { background: #fff2ec; }

.pwd-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 10px;
}

/* ---------- 小屏 ---------- */
@media (max-width: 600px) {
  .main { padding: 10px 8px 16px; }
  .modal { align-items: flex-end; padding: 0; }
  .modal-card {
    width: 100%;
    max-height: 92vh;
    border-radius: 14px 14px 0 0;
  }
  .form-row > span { flex: 0 0 76px; }
  .ch-row { grid-template-columns: 1fr; }
  .login-card { margin-top: 2vh; }
}

/* ---------- 打印：只打印 A4 介绍信 ---------- */
@media print {
  @page { size: A4; margin: 0; }

  html, body {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block;
  }

  .topbar, .toolbar, .footer, .modal, .toast, .loading, #captureHolder {
    display: none !important;
  }

  .main {
    max-width: none;
    margin: 0;
    padding: 0;
  }

  .stage {
    overflow: visible;
    padding: 0;
  }

  .stage-box {
    width: 794px !important;
    height: 1123px !important;
    margin: 0 !important;
  }

  .paper-scaler {
    transform: none !important;
  }

  .paper {
    box-shadow: none;
    page-break-after: avoid;
  }
}
