:root {
  --bg: #F5F7FA;
  --card: #FFFFFF;
  --blue: #3B82F6;
  --amber: #F59E0B;
  --green: #10B981;
  --gray: #9CA3AF;
  --text-main: #1F2937;
  --text-sub: #6B7280;
  --border: #E5E7EB;
  --canvas: #FAFAFA;
  --log-bg: #1E293B;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-main);
  font-family: "Microsoft YaHei UI", "PingFang SC", "Hiragino Sans GB", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.wrap { max-width: 1500px; margin: 0 auto; padding: 0 18px; }

.app-header {
  background: linear-gradient(135deg, #1E3A8A 0%, #2563EB 100%);
  color: #fff;
  padding: 13px 0;
  box-shadow: 0 2px 10px rgba(30, 58, 138, .25);
}
.app-header h1 { margin: 0; font-size: 19px; }
.subtitle { margin: 3px 0 0; opacity: .85; font-size: 12px; }

main.wrap { padding-top: 12px; padding-bottom: 60px; }

/* ---------- 上传卡片（紧凑一行，给结果区让出垂直空间） ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.card-title { margin: 0 0 10px; font-size: 15px; }

/* ===== 文件区：两行布局（本次核对 / 参考资料库） ===== */
.upload-rows { display: flex; flex-direction: column; gap: 10px; }
.band-title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 7px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.band-hint { font-size: 11px; font-weight: 500; color: var(--text-sub); }

/* 第一行：本次核对 */
.band-run {
  background: linear-gradient(180deg, #EFF4FF 0%, #F7FAFF 100%);
  border: 1px solid #DBE6FA;
  border-left: 3px solid var(--blue);
  border-radius: 9px;
  padding: 9px 11px;
}
.run-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px 14px;
  align-items: end;
}

/* 第二行：参考资料库 */
.ref-library {
  border: 1.5px dashed #C7D2E2;
  border-radius: 10px;
  padding: 9px 11px 11px;
  background: #FBFCFE;
}
.library-title { margin-bottom: 8px; }
.library-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}
.ref-group {
  border-radius: 9px;
  padding: 9px 11px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  align-items: end;
}
.group-l3 {
  background: #EFF4FF;
  border: 1px solid #D4E1F7;
  border-top: 3px solid var(--blue);
}
.group-l2 {
  background: #ECF7F4;
  border: 1px solid #C7E9E1;
  border-top: 3px solid #0E9F8C;
}
.group-name {
  font-size: 12.5px;
  font-weight: 800;
  margin-bottom: 0;
  color: #1E3A5F;
  display: flex;
  align-items: center;
  grid-column: 1 / -1;
}
.group-l2 .group-name { color: #0B6B5F; }

.ref-slot { margin-bottom: 0; min-width: 0; }
.ref-slot-body {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.75);
  border: 1px solid #E2E8F0;
  border-radius: 7px;
  padding: 3px;
}
.ref-status {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11.5px;
  color: var(--text-sub);
}
.ref-clear {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: #E5E7EB;
  color: #6B7280;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
  transition: all .15s;
}
.ref-clear:hover { background: #FECACA; color: #B91C1C; }
.file-item { min-width: 0; }
.file-label { display: block; font-weight: 700; margin-bottom: 4px; font-size: 13px; }
.req { color: #DC2626; font-size: 11px; font-weight: 600; }
.opt { color: var(--text-sub); font-size: 11px; font-weight: 600; }

.file-pick {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #F3F4F6;
  border-radius: 7px;
  padding: 3px;
}
.file-pick input[type="file"] { display: none; }
.file-btn {
  background: var(--amber);
  color: #fff;
  padding: 5px 12px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.file-btn:hover { filter: brightness(1.05); }
.file-name {
  flex: 1;
  color: var(--text-sub);
  font-size: 12px;
  padding: 3px 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-name.picked { color: #047857; font-weight: 600; }

.action-bar { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.btn {
  border: none;
  border-radius: 8px;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  padding: 9px 20px;
  cursor: pointer;
  transition: filter .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn-action { background: var(--blue); }
.btn-export { background: var(--green); }
.btn-export:disabled { background: #D1D5DB; color: #9CA3AF; cursor: not-allowed; }
.btn:hover:not(:disabled) { filter: brightness(1.06); }

.spinner-wrap {
  display: none;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  color: var(--blue);
  font-weight: 600;
}
.spinner-wrap.htmx-request { display: flex; }
.spinner {
  width: 20px; height: 20px;
  border: 3px solid #BFDBFE;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 结果区 ---------- */
.results { margin-top: 20px; }

.status-bar {
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 16px;
}
.status-success { background: #E8F5E9; color: #1B5E20; border: 1px solid #A5D6A7; }
.status-danger  { background: #FFEBEE; color: #B71C1C; border: 1px solid #EF9A9A; }

/* ---------- 当日参考信息（重点计划 / 时段表） ---------- */
.ref-section { margin-bottom: 16px; }
.ref-head {
  font-weight: 700;
  font-size: 15px;
  color: #1565C0;
  margin-bottom: 8px;
}
.ref-hint { font-weight: 400; font-size: 12px; color: var(--text-sub); margin-left: 6px; }
.ref-day {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  overflow: hidden;
}
.ref-summary {
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 700;
  color: #1565C0;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 10px;
}
.ref-date { white-space: nowrap; }
.ref-tag {
  font-size: 11px;
  font-weight: 600;
  color: #1D4ED8;
  background: #E3F2FD;
  border-radius: 10px;
  padding: 2px 10px;
}
.ref-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 4px 14px 12px;
}
.ref-block { border-radius: 8px; padding: 8px 10px; }
.ref-plan { background: #FAFAFA; }
.ref-sched { background: #F5F9FF; }
.ref-title { font-weight: 700; font-size: 13px; margin-bottom: 4px; color: #374151; }
.ref-text {
  margin: 0;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 260px;
  overflow-y: auto;
  color: #263238;
}

/* ---------- 横向滚动核对表 ---------- */
.table-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
  -webkit-overflow-scrolling: touch;
  max-height: 78vh;
  overflow-y: auto;
}
.cmp-table {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
}

/* 冻结：顶部表头、左侧名称列 */
.sticky-head { position: sticky; top: 0; z-index: 3; }
.sticky-col {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #EEF3FB;
  box-shadow: 3px 0 8px rgba(30, 58, 138, .14);
  border-right: 2px solid #B9C9E8;
}
thead .sticky-col { z-index: 4; background: #DCE7F8; }

.col-head {
  background: #EAF1FB;
  color: #1E3A8A;
  font-size: 12.5px;
  font-weight: 700;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid #C7D7F0;
  border-right: 1px solid #DCE6F5;
  white-space: nowrap;
}
/* D/E 参考列表头：中性灰，和核对列区分 */
.ref-head-cell {
  background: #F1F3F6 !important;
  color: #475569;
  border-bottom: 2px solid #D5DBE4;
  border-right: 1px solid #E2E6EC;
}

/* 左侧名称列：行首标尺，加深底 + 序号徽标 */
.col-name {
  text-align: left;
  vertical-align: top;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
  color: #1565C0;
  border-bottom: 4px solid #8FA9D6;
  border-right: 2px solid #B9C9E8;
  min-width: 160px;
  width: 160px;
}
.name-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #2563EB;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  margin-right: 6px;
  vertical-align: middle;
  flex-shrink: 0;
}
.name-text { display: inline; word-break: break-word; vertical-align: middle; }

/* 列宽档位 */
.w-narrow { min-width: 92px;  width: 92px; }
.w-mid    { min-width: 190px; width: 190px; }
.w-wide   { min-width: 270px; width: 270px; }
.w-xwide  { min-width: 340px; width: 340px; }
.w-ref    { min-width: 300px; width: 300px; }

/* D/E 参考列：中性灰底，不参与核对着色，格内限高滚动 */
.ref-cell {
  background: #F8FAFC;
  border-bottom: 4px solid #C2C9D4;
  border-right: 1px solid #E5E9F0;
  vertical-align: top;
  padding: 8px 10px;
}
/* 参考格内部：申报值（日期/时段）与核对内容分隔，便于对照 */
.ref-decl {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.ref-tag {
  flex-shrink: 0;
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  color: #64748B;
  background: #E2E8F0;
  border-radius: 4px;
  padding: 1px 6px;
  line-height: 1.6;
}
.ref-tag.tag-checked {
  color: #1D4ED8;
  background: #DBEAFE;
}
.ref-decl-val {
  font-weight: 800;
  font-size: 12.5px;
  color: #0F172A;
  word-break: break-word;
}
.ref-split {
  height: 0;
  border-top: 1.5px dashed #C3CCD8;
  margin: 2px 0 7px;
}
.ref-checked { display: block; }
.ref-checked .ref-tag { margin-bottom: 4px; }
.ref-text {
  margin: 0;
  font-family: Consolas, "Courier New", monospace;
  font-size: 11.5px;
  line-height: 1.6;
  color: #475569;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 150px;
  overflow-y: auto;
}
.ref-cell .muted { color: #B0B4BB; }
/* 一般重点计划 与 2号线重点计划 之间的区块分隔线（实线，比申报/核对虚线更明确） */
.ref-split.key-split {
  margin: 9px 0;
  border-top: 1px solid #93C5FD;
  border-bottom: none;
}
.line2-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.line2-head .line2-tag { margin-bottom: 0; }
.line2-date {
  font-family: Consolas, "Courier New", monospace;
  font-size: 11px;
  font-weight: 700;
  color: #1D4ED8;
  background: #EFF6FF;
  padding: 1px 7px;
  border-radius: 4px;
}

/* 2 号线重点（D 列附加区块，蓝色系，与一般重点计划明确区分） */
.line2-box {
  margin-top: 8px;
  padding: 8px 9px;
  border: 1px solid #bfdbfe;
  border-left: 4px solid #2563eb;
  border-radius: 6px;
  background: #eff6ff;
}
.line2-tag {
  color: #fff !important;
  background: #2563eb !important;
  border-color: #2563eb !important;
}
.line2-box .ref-text {
  color: #1e3a8a;
  max-height: 150px;
  overflow-y: auto;
}

/* 每条计划之间粗分隔（4px），避免横滑时串行 */
.cell {
  vertical-align: top;
  padding: 8px 10px;
  border-bottom: 4px solid #C2C9D4;
  border-right: 1px solid #F1F3F6;
}
.trow + .trow td,
.trow + .trow th { border-top: 0; }
.cell-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.cell-mark { font-size: 12px; font-weight: 700; white-space: nowrap; }
.mark-ok   { color: #15803D; }
.mark-err  { color: #B71C1C; }
.mark-warn { color: #B45309; }

.ok-cell  { background: #FCFEFD; }
.diff-cell {
  background: #FFF7F7;
  box-shadow: inset 3px 0 0 #EF4444;
}
.warn-cell {
  background: #FFFCF3;
  box-shadow: inset 3px 0 0 #F59E0B;
}
.empty-cell { background: #FAFAFA; text-align: center; }
.empty-cell .muted { color: #B0B4BB; }

.row-notfound .sticky-col,
.row-notfound .nf-cell { background: #FEF2F2; }
.nf-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: #DC2626;
  border-radius: 4px;
  padding: 1px 7px;
  margin-bottom: 5px;
}
.nf-note { color: #B91C1C; font-size: 12px; font-weight: 600; }

.accept-rev {
  font-size: 11.5px;
  font-weight: 600;
  color: #B71C1C;
  background: #fff;
  border: 1px solid #EF9A9A;
  border-radius: 6px;
  padding: 1px 7px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.accept-rev input { margin: 0; cursor: pointer; }

.sub-label { font-size: 11.5px; font-weight: 700; padding: 2px 0; }
.sub-label.decl { color: #8D6E63; }

.cell-text {
  margin: 0;
  padding: 2px 0 4px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow-y: auto;
}
.decl-text { color: #3E2723; }
.ok-text { color: var(--text-sub); }

.divider { height: 1px; margin: 5px 0; }
.div-diff { background: #F3C2C2; }
.div-warn { background: #F3D9A4; }

.tpl-diff { color: #B71C1C; }
.tpl-warn { color: #B45309; }
.tpl-text-diff { color: #B71C1C; }
.tpl-text-warn { color: #B45309; }

.tagged { margin-top: 2px; }
.tag-line {
  display: flex;
  gap: 6px;
  align-items: baseline;
  padding: 3px 0;
  font-family: Consolas, monospace;
  font-size: 12px;
  border-bottom: 1px dashed rgba(0,0,0,.08);
}
.tag-badge {
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  color: #fff;
}
.tag-ok .tag-badge   { background: #2E7D32; }
.tag-miss .tag-badge { background: #C62828; }
.tag-add .tag-badge  { background: #F57C00; }
.tag-err .tag-badge  { background: #C62828; }
.tag-text { word-break: break-word; }

.f-warning {
  background: #FEF3C7;
  color: #B45309;
  font-weight: 700;
  font-size: 11.5px;
  padding: 5px 8px;
  margin-top: 6px;
  border-radius: 4px;
}

.table-hint {
  margin: 10px 2px 0;
  font-size: 12.5px;
  color: var(--text-sub);
}

.muted { color: #757575; }

/* ---------- 日志 ---------- */
.log-panel {
  margin-top: 20px;
  background: var(--log-bg);
  border-radius: 10px;
  padding: 10px 14px;
  color: #CBD5E1;
}
.log-panel summary {
  cursor: pointer;
  font-weight: 700;
  color: #E2E8F0;
  user-select: none;
}
.log-body { margin-top: 10px; max-height: 260px; overflow-y: auto; font-family: Consolas, monospace; font-size: 12.5px; }
.log-line { padding: 2px 0; white-space: pre-wrap; word-break: break-word; }
.log-info { color: #93C5FD; }
.log-success { color: #4ADE80; }
.log-warn { color: #FBBF24; }
.log-error { color: #F87171; }

.error-box {
  background: #FEF2F2;
  border: 1px solid #FCA5A5;
  border-radius: 10px;
  padding: 16px;
  color: #991B1B;
  font-weight: 600;
}
.error-title { font-size: 15px; margin-bottom: 8px; }

/* ---------- 移动端 ---------- */
@media (max-width: 640px) {
  .run-grid { grid-template-columns: 1fr; }
  .library-groups { grid-template-columns: 1fr; }
  .ref-group { grid-template-columns: 1fr; }
  .action-bar .btn { flex: 1; }
  .app-header h1 { font-size: 19px; }
  .col-name { min-width: 130px; width: 130px; }
  .w-ref { min-width: 230px; width: 230px; }
  .name-index { width: 20px; height: 20px; font-size: 11px; }
}
