/* ============================================================
   党报党刊发票识别 - 样式
   ============================================================ */
:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #1d4ed8;
  --primary-dark: #1e40af;
  --danger: #dc2626;
  --ok: #059669;
  --warn: #d97706;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "微软雅黑",
               "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- 顶栏 ---------- */
.topbar {
  background: #0f172a;
  color: #e2e8f0;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand {
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .5px;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a {
  color: #cbd5e1;
  padding: 6px 12px;
  border-radius: 6px;
  white-space: nowrap;
}
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.14); color: #fff; }

.userbox { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.username { color: #e2e8f0; font-weight: 600; }
.badge-role, .badge-user {
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(59,130,246,.25);
  color: #bfdbfe;
}
.badge-user { background: rgba(148,163,184,.2); color: #cbd5e1; }
.badge-sub { background: rgba(16,185,129,.2); color: #a7f3d0; }

/* ---------- 布局 ---------- */
.container {
  max-width: 1180px;
  margin: 24px auto 40px;
  padding: 0 20px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  margin-bottom: 20px;
}
.card.narrow { max-width: 520px; margin-left: auto; margin-right: auto; }
.card.center { text-align: center; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.card h2 {
  margin: 0 0 10px;
  font-size: 17px;
  font-weight: 700;
}

/* ---------- 表单 ---------- */
label {
  display: block;
  margin-bottom: 14px;
  font-weight: 600;
  color: #374151;
}
input[type=text], input[type=password], input[type=date] {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
input[type=text]:focus, input[type=password]:focus, input[type=date]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}

select {
  padding: 9px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}

.inline-form { display: flex; gap: 10px; align-items: center; margin: 0; }
.inline-form.wrap { flex-wrap: wrap; }
.inline-form input[type=text] { width: 260px; margin-top: 0; }
.prefix-label { font-weight: 600; color: #374151; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.inline-label { display: flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; }
.inline-label input[type=date] { width: auto; margin-top: 0; }

button { font-family: inherit; }

.btn {
  display: inline-block;
  padding: 9px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: #93a3c4; cursor: not-allowed; }
.btn-ghost { background: #fff; color: #374151; border-color: #d1d5db; }
.btn-ghost:hover { background: #f9fafb; }
.btn-block { width: 100%; }
.btn.danger, .link-btn.danger { color: var(--danger); }

.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--primary);
  font-size: 14px;
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }

.inline { display: inline; margin: 0; }

.hint { color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: Consolas, "Courier New", monospace; }
.ellipsis {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 上传区 ---------- */
.dropzone {
  border: 2px dashed #c7d2fe;
  border-radius: var(--radius);
  background: #f8faff;
  padding: 34px 20px;
  text-align: center;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.dropzone:hover, .dropzone.dragging {
  background: #eef2ff;
  border-color: var(--primary);
}
.dz-icon { font-size: 34px; color: var(--primary); line-height: 1; }
.dz-text { margin-top: 8px; color: #4b5563; }

.file-list { margin-top: 14px; text-align: left; max-width: 640px; margin-left: auto; margin-right: auto; }
.file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  margin-top: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  word-break: break-all;
}
.file-item .rm {
  border: none;
  background: none;
  color: #9ca3af;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.file-item .rm:hover { color: var(--danger); }

.actions { display: flex; align-items: center; gap: 14px; margin-top: 16px; flex-wrap: wrap; }

/* ---------- 表格 ---------- */
.table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.table th, .table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.table th {
  background: #f8fafc;
  color: #4b5563;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.table tbody tr:hover { background: #fafbff; }
.row-fail td { color: #b91c1c; }
.total-row td {
  background: #f8fafc;
  font-weight: 600;
}

/* 上传记录表：列宽按比例固定，长文件名（数字串不会自动断行）在格内折行，
   否则会把表格撑出卡片白框 */
.records-wrap { overflow-x: auto; }
.records-table { table-layout: fixed; }
.records-table td { overflow-wrap: anywhere; }
.records-table col.col-time   { width: 13.5%; }
.records-table col.col-user   { width: 9.5%; }
.records-table col.col-file   { width: 18%; }
.records-table col.col-status { width: 8.5%; }
.records-table col.col-reason { width: 14.5%; }
.records-table col.col-no     { width: 18.5%; }
.records-table col.col-act    { width: 17.5%; }
/* 操作列三个链接允许换行，避免在固定列宽下溢出到相邻格 */
.records-table td.cell-act { white-space: normal; }

/* 无归属账号（归属账号已被删除的发票） */
.orphan-row td {
  background: #fffbeb;
  color: #92400e;
}.badge-orphan {
  font-size: 12px;
  padding: 1px 8px;
  margin-left: 6px;
  border-radius: 999px;
  background: #fef3c7;
  color: #92400e;
  white-space: nowrap;
}

/* 二级账号下面的下级明细行（缩进，不参与合计） */
.detail-row td {
  background: #fcfcfe;
  color: #64748b;
  font-size: 12.5px;
  padding-top: 5px;
  padding-bottom: 5px;
}
.detail-row:hover td { background: #f7f8fd; }
.detail-cell { padding-left: 20px !important; }
.detail-cell .branch {
  display: inline-block;
  width: 14px;
  color: #cbd5e1;
  font-size: 12px;
}
.target-detail .qty-line { font-size: 11.5px; }
.target-detail .pbar { height: 5px; margin-top: 3px; }

/* 累计表里的「今日上传」明细列 */
.today-col { white-space: nowrap; }
.today-cell {
  font-size: 12px;
  color: #4b5563;
  line-height: 1.55;
  min-width: 96px;
  max-width: 220px;
}

/* ---------- 任务指标 ---------- */
.table-wrap { overflow-x: auto; }
.target-table th { white-space: nowrap; }
.target-table td { vertical-align: middle; }

/* 参考数量表：整页往下拉时表头吸顶（外层不能是滚动容器，否则 sticky 失效） */
.target-wrap { overflow: visible; }
.target-table thead th {
  position: sticky;
  top: 56px;                  /* 顶栏高度 */
  z-index: 6;
  background: #f8fafc;
  box-shadow: inset 0 -1px 0 var(--line);
}

/* 窗口偏窄时列会被挤得换行，改为横向滚动并放弃吸顶 */
@media (max-width: 1150px) {
  .table-wrap.target-wrap { overflow-x: auto; }
  .target-table { min-width: 1000px; }
  .target-table thead th { position: static; box-shadow: none; }
}
.unit-cell {
  max-width: 210px;
  white-space: normal;
  word-break: break-all;
  line-height: 1.4;
}
.target-cell { min-width: 92px; }
.money-cell { min-width: 122px; }
.qty-line {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  font-size: 11.5px;
  color: #374151;
  line-height: 1.5;
}
.qty-line .pct { color: var(--muted); font-variant-numeric: tabular-nums; }
.pbar {
  height: 6px;
  margin-top: 3px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}
.pbar > i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
}
.pbar.ok  > i { background: var(--ok); }
.pbar.mid > i { background: #f59e0b; }
.pbar.low > i { background: var(--danger); }

/* 指标填写表格：固定列宽，避免输入框把表格撑出卡片 */
#target-table { table-layout: fixed; }
#target-table th:nth-child(1) { width: 24%; }
#target-table th:nth-child(2) { width: 15%; }
#target-table th:nth-child(n+3):nth-child(-n+9) { width: 7%; }
#target-table th:last-child { width: 58px; }
#target-table th, #target-table td { padding: 7px 5px; }
#target-table td:last-child { text-align: center; }
#target-table td:last-child .link-btn { white-space: nowrap; }

.grid-input {
  width: 100%;
  min-width: 0;
  padding: 4px 5px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
}
.grid-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(29, 78, 216, .12);
}

/* ---------- 状态 ---------- */
.status {
  display: inline-block;
  padding: 1px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #f3f4f6;
  color: #4b5563;
  white-space: nowrap;
}
.status-queued { background: #fef3c7; color: #92400e; }
.status-processing { background: #dbeafe; color: #1e40af; }
.status-done { background: #d1fae5; color: #065f46; }
.status-failed { background: #fee2e2; color: #991b1b; }

/* ---------- 任务详情 ---------- */
.kv {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 6px 16px;
  margin: 12px 0;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.progress-box {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  padding: 14px 16px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  color: #1e40af;
}
.spinner {
  width: 18px; height: 18px;
  border: 3px solid #bfdbfe;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.done-box {
  margin-top: 14px;
  padding: 16px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-radius: 8px;
}
.done-box .btn { margin-top: 8px; }

/* 结果结论文本 */
.summary-box p { margin: 0 0 6px; line-height: 1.7; }
.summary-box p:first-child { font-weight: 600; }

.hidden { display: none !important; }

/* ---------- 提示 ---------- */
.flashes { margin-bottom: 14px; }
.flash {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.7;          /* 提示语变长（带上级单位名）后不至于挤成一坨 */
  overflow-wrap: anywhere;
}
.flash-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.flash-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

.empty { color: var(--muted); text-align: center; padding: 24px 0; }

/* ---------- 登录页 ---------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 14px;
  padding: 34px 32px 26px;
  box-shadow: 0 20px 40px rgba(0,0,0,.25);
}
.login-card h1 { font-size: 21px; margin: 0 0 4px; text-align: center; }
.login-sub { color: var(--muted); text-align: center; margin: 0 0 20px; }
.login-owner {
  margin: 0 0 18px;
  padding: 8px 12px;
  border-radius: 8px;
  background: #f4f7fc;
  border: 1px solid #e3eaf5;
  color: #4b5563;
  font-size: 12.5px;
  line-height: 1.55;
  text-align: center;
}

.login-tip { color: var(--muted); font-size: 12px; text-align: center; margin: 16px 0 0; }

/* ---------- 页脚 ---------- */
.footer {
  text-align: center;
  color: #9ca3af;
  font-size: 12px;
  padding: 0 20px 24px;
}
.footer p { margin: 4px 0; }
.footer-note { color: #6b7280; }

.notice {
  margin: 14px 0 0;
  padding: 10px 14px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  color: #92400e;
  font-size: 13px;
  line-height: 1.7;
}

/* 完成提醒提示条 */
.notify-tip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.notify-tip .btn {
  padding: 5px 14px;
  font-size: 13px;
  white-space: nowrap;
}

/* 上传页「发票归属账号」 */
.owner-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding: 10px 14px;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}
.owner-row label { margin: 0; font-weight: 600; }
.owner-row select { min-width: 170px; }
.owner-row .hint { color: #6b7280; font-size: 12px; }

/* 上传记录：改归属（行内展开） */
.owner-edit { display: inline-block; vertical-align: top; max-width: 100%; }
.owner-edit > summary {
  cursor: pointer;
  color: var(--primary);
  font-size: 13px;
  list-style: none;
  display: inline-block;
}
.owner-edit > summary::-webkit-details-marker { display: none; }
.owner-edit > summary::after { content: " ▾"; }
.owner-edit[open] > summary::after { content: " ▴"; }
.owner-edit-form {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: 8px 0 6px;
}
/* 列宽固定后，下拉框收起自身宽度，别顶出单元格 */
.owner-edit-form select { padding: 4px 8px; font-size: 13px; min-width: 0; max-width: 100%; }
.owner-edit-form .link-btn { font-size: 13px; }

/* ---------- 上传记录状态色 ---------- */
.status-recorded { background: #d1fae5; color: #065f46; }
.status-duplicate { background: #fef3c7; color: #92400e; }
.status-no001 { background: #f1f5f9; color: #475569; }
.status-out_of_period { background: #e0e7ff; color: #3730a3; }
.status-incomplete { background: #fee2e2; color: #991b1b; }

/* 管理员手动入库标记 */
.badge-manual {
  font-size: 12px;
  padding: 1px 8px;
  margin-left: 6px;
  border-radius: 999px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #047857;
  white-space: nowrap;
}
.manual-note-inline {
  display: block;
  margin-top: 3px;
  color: #6b7280;
  font-size: 12px;
}

/* 手动入库页 */
.manual-info th { width: 110px; color: var(--muted); font-weight: 600; }
.manual-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 4px 14px;
  margin-bottom: 6px;
}
.manual-grid label { margin-bottom: 10px; font-size: 13px; }
.manual-grid input[type=number] {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}
.manual-grid input[type=number]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}
.manual-note textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.6;
  resize: vertical;
}
.manual-note textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}
.manual-clear { margin-top: 14px; font-size: 13px; }

/* 窗口偏窄时记录表改为横向滚动，避免 7 列被挤成竖排 */
@media (max-width: 900px) {
  .records-wrap .records-table { min-width: 960px; }
}

@media (max-width: 720px) {
  .topbar-inner { height: auto; flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .nav { order: 3; width: 100%; }
  .container { padding: 0 12px; }
  .card { padding: 16px; }
  .table { display: block; overflow-x: auto; white-space: nowrap; }
  /* 上传记录表改为外层容器横向滚动，保留固定列宽与格内折行 */
  .records-table { display: table; white-space: normal; }
  /* 窄屏表格自身横向滚动，吸顶表头会错位，这里退回普通表头 */
  .table-wrap.target-wrap { overflow-x: auto; }
  .target-table thead th { position: static; box-shadow: none; }
  .inline-form { flex-wrap: wrap; }
  .inline-form input[type=text] { width: 100%; }
}
