/* ==========================================================================
   收发记录系统 —— 样式表
   ========================================================================== */

:root {
  --c-primary: #1f6feb;
  --c-primary-dark: #1758c0;
  --c-out: #e8710a;
  --c-out-bg: #fff5eb;
  --c-in: #1a9c62;
  --c-in-bg: #eefaf3;
  --c-text: #1f2430;
  --c-text-2: #5b6474;
  --c-muted: #8b94a6;
  --c-line: #e2e6ee;
  --c-line-2: #edf0f6;
  --c-bg: #f4f6fa;
  --c-card: #ffffff;
  --c-danger: #d93a3a;
  --shadow-sm: 0 1px 2px rgba(23, 32, 56, .06), 0 1px 3px rgba(23, 32, 56, .04);
  --shadow-md: 0 4px 14px rgba(23, 32, 56, .08), 0 1px 3px rgba(23, 32, 56, .05);
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font: 14px/1.6 "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ---------------------------- 顶部栏 ---------------------------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: #fff;
  border-bottom: 1px solid var(--c-line);
  box-shadow: var(--shadow-sm);
}

.appbar-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 20px;
  min-height: 60px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  flex: 0 1 auto;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #2b7cf0, #1a9c62);
  color: #fff;
  font-weight: 700;
  display: grid;
  place-items: center;
  font-size: 16px;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text b { font-size: 17px; letter-spacing: .5px; white-space: nowrap; }
.brand-text small { color: var(--c-muted); font-size: 11.5px; white-space: nowrap; }

.nav { display: flex; gap: 4px; flex: 1; }

.nav a {
  padding: 7px 14px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--c-text-2);
  font-size: 14px;
  white-space: nowrap;
}

.nav a:hover { background: var(--c-line-2); color: var(--c-text); }
.nav a.active { background: #eaf2ff; color: var(--c-primary); font-weight: 600; }

.appbar-right { display: flex; align-items: center; gap: 8px; flex: none; }

.save-chip, .db-chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--c-line);
  color: var(--c-text-2);
  background: #fbfcfe;
  white-space: nowrap;
}

.save-chip.saving { color: #b26b00; border-color: #ffe0a8; background: #fff8e8; }
.save-chip.saved { color: var(--c-in); border-color: #bfe8d3; background: var(--c-in-bg); }
.save-chip.error { color: var(--c-danger); border-color: #f5c2c2; background: #fdf0f0; }

/* ---------------------------- 主体布局 ---------------------------- */
#main {
  max-width: 1360px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: 90px;
}

.view { display: none; }
.view.active { display: block; animation: fade .18s ease; }

@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* ---------------------------- 首页 ---------------------------- */
.hero { margin: 6px 0 22px; }
.hero h1 { margin: 0 0 6px; font-size: 24px; letter-spacing: .5px; }
.hero p { margin: 0; color: var(--c-text-2); }
.hero b { color: var(--c-primary); }

.entry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.entry-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 22px 22px 18px;
  background: var(--c-card);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}

.entry-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.entry-card:active { transform: none; }

.entry-icon { font-size: 30px; line-height: 1; }
.entry-title { font-size: 22px; font-weight: 700; letter-spacing: 4px; }
.entry-desc { color: var(--c-text-2); font-size: 13px; min-height: 42px; }
.entry-action { font-size: 13px; font-weight: 600; margin-top: 4px; }

.entry-out { border-top: 3px solid var(--c-out); }
.entry-out .entry-action { color: var(--c-out); }
.entry-in { border-top: 3px solid var(--c-in); }
.entry-in .entry-action { color: var(--c-in); }
.entry-list { border-top: 3px solid var(--c-primary); }
.entry-list .entry-action { color: var(--c-primary); }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.stat {
  background: var(--c-card);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.stat .stat-num { font-size: 22px; font-weight: 700; }
.stat .stat-label { color: var(--c-muted); font-size: 12px; }

.notice {
  margin-top: 20px;
  background: #fff;
  border: 1px solid var(--c-line);
  border-left: 3px solid var(--c-primary);
  border-radius: var(--radius);
  padding: 16px 20px 14px;
  box-shadow: var(--shadow-sm);
}

.notice-title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 10px;
  color: var(--c-text);
}

.notice-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 7px;
}

.notice-list li {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  color: var(--c-text-2);
  font-size: 13.5px;
  line-height: 1.7;
}

.notice-list li > span:last-child { flex: 1 1 auto; min-width: 0; }

.notice-list .dot {
  flex: none;
  width: 6px;
  height: 6px;
  margin-top: 8px;
  border-radius: 50%;
  background: #b9c6dc;
}

.notice-list b {
  color: var(--c-text);
  white-space: nowrap;          /* 短词不拆行，避免「保存单据」被拆成两行 */
  font-weight: 600;
}

/* ---------------------------- 页面标题 ---------------------------- */
.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 4px 0 14px;
  flex-wrap: wrap;
}

.view-head h2 { margin: 0; font-size: 19px; display: flex; align-items: center; gap: 10px; }
.view-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.tag {
  display: inline-block;
  font-size: 13px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 6px;
  letter-spacing: 2px;
}

.tag-out { background: var(--c-out-bg); color: var(--c-out); border: 1px solid #ffd9ad; }
.tag-in { background: var(--c-in-bg); color: var(--c-in); border: 1px solid #bfe8d3; }

/* ---------------------------- 卡片 ---------------------------- */
.card {
  background: var(--c-card);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  overflow: hidden;
}

.card-title {
  padding: 12px 16px;
  border-bottom: 1px solid var(--c-line-2);
  font-weight: 600;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  background: #fcfdff;
}

.card-hint { font-weight: 400; font-size: 12px; color: var(--c-muted); }

/* ---------------------------- 表单字段 ---------------------------- */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px 16px;
  padding: 16px;
}

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 12.5px; color: var(--c-text-2); font-weight: 600; }
.field-wide { grid-column: 1 / -1; }

input[type="text"], input[type="date"], input[type="search"], select, textarea {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--c-line);
  border-radius: 7px;
  background: #fff;
  color: var(--c-text);
  font: inherit;
  outline: none;
  transition: border-color .12s, box-shadow .12s, background .12s;
}

input:hover, select:hover, textarea:hover { border-color: #cbd3e1; }

input:focus, select:focus, textarea:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, .13);
}

input::placeholder { color: #b3bac7; }

input.flash { background: #fffbdd; transition: background .3s; }

/* ---------------------------- 表格 ---------------------------- */
.table-wrap { width: 100%; overflow-x: auto; }

table.sheet {
  width: 100%;
  min-width: 940px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

table.sheet th, table.sheet td {
  border-bottom: 1px solid var(--c-line-2);
  border-right: 1px solid var(--c-line-2);
  padding: 4px 6px;
  text-align: left;
  font-weight: 400;
  vertical-align: middle;
  font-size: 13px;
}

table.sheet th:last-child, table.sheet td:last-child { border-right: 0; }

table.sheet thead th {
  background: #f7f9fc;
  color: var(--c-text-2);
  font-weight: 600;
  font-size: 12.5px;
  white-space: nowrap;
  padding: 9px 8px;
  border-bottom: 1px solid var(--c-line);
  position: sticky;
  top: 0;
  z-index: 1;
}

table.sheet thead th i { color: var(--c-danger); font-style: normal; }

table.sheet tbody tr:hover { background: #fafbfe; }

table.sheet td { padding: 3px 4px; }

table.sheet input {
  border: 1px solid transparent;
  background: transparent;
  padding: 6px 7px;
  border-radius: 6px;
}

table.sheet input:hover { border-color: var(--c-line); background: #fff; }
table.sheet input:focus { border-color: var(--c-primary); background: #fff; }

td.rownum {
  text-align: center;
  color: var(--c-muted);
  background: #fafbfd;
  font-size: 12px;
}

td.qtycell input { text-align: right; font-variant-numeric: tabular-nums; }

/* 关键项未填时的提示底色 */
table.sheet input.cell-warn { background: #fff6f6; border-color: #f4d2d0; }
table.sheet input.cell-warn:focus { background: #fff; border-color: var(--c-primary); }

.row-del {
  border: 0;
  background: transparent;
  color: var(--c-muted);
  cursor: pointer;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 15px;
  line-height: 1;
}

.row-del:hover { background: #fdeceb; color: var(--c-danger); }

.table-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--c-line-2);
  background: #fcfdff;
  flex-wrap: wrap;
}

.table-foot-left, .table-foot-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.table-foot-right { margin-left: auto; }

.sum { font-size: 13px; color: var(--c-text-2); }
.warn { font-size: 12.5px; color: #b26b00; }

.muted { color: var(--c-muted); font-size: 12.5px; }

/* ---------------------------- 未保存提醒 / 修改提示条 ---------------------------- */
.save-chip.dirty { color: #b26b00; border-color: #ffe0a8; background: #fff8e8; }
.savedot.dirty { background: #e8a317; }

.btn-save { min-width: 116px; }

.edit-banner {
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid #ffd9ad;
  border-left: 3px solid var(--c-out);
  background: var(--c-out-bg);
  color: #8a4b06;
  font-size: 13px;
}

.edit-banner[hidden] { display: none; }

.stickybar .btn-primary { padding: 6px 16px; }

/* ---------------------------- 按钮 ---------------------------- */
.btn {
  padding: 7px 14px;
  border-radius: 7px;
  border: 1px solid var(--c-line);
  background: #fff;
  color: var(--c-text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, box-shadow .12s;
}

.btn:hover { background: #f4f7fc; border-color: #cbd3e1; }
.btn:active { background: #eaeff7; }

.btn-primary {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover { background: var(--c-primary-dark); border-color: var(--c-primary-dark); }
.btn-primary:active { background: #144a9e; }

.btn-danger { color: var(--c-danger); }
.btn-danger:hover { background: #fdeceb; border-color: #f3c3c1; }

.btn-mini { padding: 4px 9px; font-size: 12.5px; border-radius: 6px; }

/* ---------------------------- 底部保存状态条 ---------------------------- */
.stickybar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(6px);
  border-top: 1px solid var(--c-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 20px;
  box-shadow: 0 -2px 10px rgba(23, 32, 56, .05);
}

.stickybar-left { display: flex; align-items: center; gap: 8px; max-width: 1360px; }
.appbar-inner, .stickybar-left, .stickybar-right { }

.savedot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c-muted);
  flex: none;
}

.savedot.saving { background: #e8a317; }
.savedot.saved { background: var(--c-in); }
.savedot.error { background: var(--c-danger); }

.savedms { font-size: 12.5px; color: var(--c-text-2); }

/* ---------------------------- 筛选区 ---------------------------- */
.filter-grid {
  display: grid;
  grid-template-columns: 150px 160px 160px 1fr auto;
  gap: 12px 14px;
  padding: 16px;
  align-items: end;
}

.field-search { min-width: 200px; }
.field-btns { flex-direction: row; align-items: center; gap: 6px; }

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--c-line-2);
  background: #fcfdff;
  flex-wrap: wrap;
}

.list-tabs { display: flex; gap: 6px; }

.list-tabs button {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--c-line);
  background: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  color: var(--c-text-2);
}

.list-tabs button b { font-weight: 600; margin-left: 4px; color: var(--c-muted); }
.list-tabs button.active { background: #eaf2ff; border-color: #b8d2ff; color: var(--c-primary); font-weight: 600; }
.list-tabs button.active b { color: var(--c-primary); }

.sheet-list { min-width: 1240px; }
.sheet-list td { padding: 7px 8px; word-break: break-word; }
.sheet-list td.num { text-align: right; font-variant-numeric: tabular-nums; }
.sheet-list td.center { text-align: center; color: var(--c-muted); font-size: 12px; }
.sheet-list tr.record-start td { border-top: 1px solid var(--c-line); }
.sheet-list .doc-no { font-weight: 600; color: var(--c-primary); }
.sheet-list .op { display: flex; gap: 4px; }

.empty {
  padding: 44px 20px;
  text-align: center;
  color: var(--c-muted);
}

.empty b { display: block; font-size: 15px; color: var(--c-text-2); margin-bottom: 6px; }

/* ---------------------------- 提示 / 弹窗 ---------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 76px;
  transform: translate(-50%, 16px);
  background: #1f2430;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
  z-index: 80;
  max-width: 80vw;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #b62c2c; }
.toast.ok { background: #17794f; }

.modal[hidden] { display: none; }
.modal { position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-mask { position: absolute; inset: 0; background: rgba(18, 24, 38, .45); }

.modal-box {
  position: relative;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 18px 50px rgba(15, 22, 40, .3);
  max-width: 860px;
  width: 100%;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.modal-x { border: 0; background: transparent; font-size: 22px; line-height: 1; color: var(--c-muted); cursor: pointer; }
.modal-x:hover { color: var(--c-text); }

.modal-body { padding: 18px; overflow: auto; }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--c-line-2);
  background: #fcfdff;
}

.doc-view h3 { margin: 0 0 4px; font-size: 18px; }
.doc-view .doc-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 6px 18px; margin: 12px 0 16px; }
.doc-view .doc-meta div { font-size: 13px; color: var(--c-text-2); }
.doc-view .doc-meta b { color: var(--c-text); font-weight: 600; }
.doc-view table { width: 100%; border-collapse: collapse; font-size: 13px; }
.doc-view th, .doc-view td { border: 1px solid var(--c-line); padding: 6px 8px; text-align: left; }
.doc-view th { background: #f5f8fd; font-weight: 600; }
.doc-view td.num { text-align: right; }

/* ---------------------------- 打印 ---------------------------- */
.view-print { display: none; }

@media print {
  body { background: #fff; }
  .appbar, #main, .stickybar, .toast, .modal { display: none !important; }
  .view-print { display: block; padding: 0 6mm; }
  .view-print h3 { margin: 0 0 6px; }
  .view-print .doc-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; margin: 10px 0; font-size: 12px; }
  .view-print table { width: 100%; border-collapse: collapse; font-size: 12px; }
  .view-print th, .view-print td { border: 1px solid #999; padding: 5px 6px; }
  .view-print th { background: #eee; }
  @page { margin: 12mm; }
}

/* ---------------------------- 小屏适配 ---------------------------- */
@media (max-width: 980px) {
  .filter-grid { grid-template-columns: 1fr 1fr; }
  .field-btns { grid-column: 1 / -1; }
}

@media (max-width: 720px) {
  .appbar-inner { height: auto; padding: 10px 12px; flex-wrap: wrap; gap: 10px; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  .brand-text b { font-size: 15.5px; }
  .brand-text small { font-size: 11px; }
  #main { padding: 12px; padding-bottom: 100px; }
  .field-grid { grid-template-columns: 1fr; }
  .filter-grid { grid-template-columns: 1fr; }
  .hero h1 { font-size: 20px; }
  .entry-title { font-size: 19px; }
  .stickybar { padding: 8px 12px; }
}

/* ==========================================================================
   登录页（服务器模式）与服务器模式下的顶部控件
   ========================================================================== */

.login-body {
  background: linear-gradient(160deg, #eef3fb 0%, #f7f9fc 45%, #eef7f2 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.login-wrap { width: 100%; max-width: 400px; }

.login-card {
  background: #fff;
  border: 1px solid var(--c-line);
  border-radius: 14px;
  box-shadow: 0 12px 34px rgba(23, 32, 56, .10), 0 2px 6px rgba(23, 32, 56, .05);
  padding: 28px 26px 22px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--c-line-2);
}

.login-brand .brand-mark { width: 42px; height: 42px; font-size: 19px; border-radius: 11px; }
.login-brand b { display: block; font-size: 19px; letter-spacing: .5px; }
.login-brand small { color: var(--c-muted); font-size: 12px; }

.login-btn {
  width: 100%;
  margin-top: 16px;
  padding: 11px;
  font-size: 15px;
  letter-spacing: 2px;
}

.login-btn:disabled { opacity: .65; cursor: default; }

.login-msg {
  margin-top: 12px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.6;
}

.login-msg.err { background: #fdf0f0; border: 1px solid #f5c2c2; color: #a82424; }
.login-msg.ok { background: var(--c-in-bg); border: 1px solid #bfe8d3; color: #147a4d; }

.login-tip {
  margin: 16px 0 0;
  color: var(--c-muted);
  font-size: 12px;
  line-height: 1.7;
  text-align: center;
}

/* 顶部：当前登录人 + 小按钮 */
#userChip {
  background: #eaf2ff;
  border-color: #c7dcff;
  color: var(--c-primary);
  font-weight: 600;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--c-text-2);
  white-space: nowrap;
  cursor: pointer;
}

.inline-check input { width: auto; }

#usersModal .card { box-shadow: none; }
#usersModal .table-foot { background: #fcfdff; }
