/* ================= 变量与重置 ================= */
:root {
  --blue: #1E88E5;
  --blue-dark: #1565C0;
  --blue-light: #E3F2FD;
  --green: #2E7D32;
  --green-light: #E8F5E9;
  --red: #e53935;
  --red-light: #FDECEA;
  --orange: #F57C00;
  --orange-light: #FFF3E0;
  --text: #212121;
  --text-2: #757575;
  --text-3: #9E9E9E;
  --bg: #F5F6F8;
  --card: #FFFFFF;
  --line: #ECECEC;
  --radius: 14px;
  --shadow: 0 1px 4px rgba(0,0,0,.06);
  --tabbar-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --content-w: 1160px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh; /* 旧内核回退 */
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; font-size: 1rem; cursor: pointer; border: none; background: none; }
input, select, textarea {
  font-family: inherit; font-size: 1rem;
  width: 100%; padding: 11px 13px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #FAFAFA; color: var(--text); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); background: #fff; }

/* ================= 通用组件 ================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 20px; border-radius: 10px;
  font-weight: 600; transition: opacity .15s, transform .05s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue-dark); }
.btn-ghost { background: var(--blue-light); color: var(--blue-dark); }
.btn-danger { background: var(--red-light); color: var(--red); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: .875rem; border-radius: 8px; }

.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}

.page-header {
  padding: calc(14px + var(--safe-t)) 16px 6px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  max-width: var(--content-w); margin: 0 auto; width: 100%;
}
.page-header h2 { font-size: 1.3rem; font-weight: 700; }

.empty { text-align: center; color: var(--text-3); font-size: .9rem; padding: 34px 0; }
.empty .emoji { font-size: 2.2rem; display: block; margin-bottom: 6px; }

/* ================= 登录层 ================= */
.auth-screen {
  min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 24px; padding-top: calc(24px + var(--safe-t));
  background: linear-gradient(160deg, var(--blue) 0%, var(--blue-dark) 100%);
}
.auth-card {
  width: 100%; max-width: 380px; background: #fff;
  border-radius: 20px; padding: 34px 26px 26px; text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,.18);
}
.auth-logo { font-size: 3rem; }
.auth-card h1 { font-size: 1.35rem; margin: 8px 0 4px; }
.auth-sub { color: var(--text-2); font-size: .875rem; margin-bottom: 22px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-toggle { color: var(--blue); font-size: .875rem; margin-top: 16px; }
.auth-error { color: var(--red); font-size: .85rem; margin-top: 10px; min-height: 1.2em; }

/* ================= 主布局 ================= */
.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

#views { flex: 1; width: 100%; max-width: var(--content-w); margin: 0 auto; padding: 14px 16px 40px; }
.view { display: none; animation: fadeIn .18s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* 顶部导航（桌面） */
.topnav {
  background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
  padding-top: var(--safe-t);
}
.topnav-inner {
  max-width: var(--content-w); margin: 0 auto;
  display: flex; align-items: center; gap: 26px; padding: 10px 16px;
}
.topnav-brand { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.topnav-links { display: flex; gap: 4px; flex: 1; }
.topnav-link {
  padding: 7px 14px; border-radius: 8px;
  color: var(--text-2); font-size: .95rem; font-weight: 500;
}
.topnav-link:hover { color: var(--text); background: var(--bg); }
.topnav-link.active { color: var(--blue-dark); background: var(--blue-light); font-weight: 600; }
.topnav-right { display: flex; align-items: center; gap: 10px; }
.topnav-user { color: var(--text-3); font-size: .8rem; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 底部 Tab（手机） */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex; background: #fff;
  border-top: 1px solid var(--line);
  z-index: 50;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; color: var(--text-3); font-size: .7rem;
}
.tab-icon { font-size: 1.4rem; line-height: 1; filter: grayscale(1) opacity(.55); transition: filter .15s; }
.tab.active { color: var(--blue-dark); font-weight: 600; }
.tab.active .tab-icon { filter: none; }

@media (max-width: 767px) {
  .topnav { display: none; }
  #views { padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); }
}
@media (min-width: 768px) {
  .tabbar { display: none; }
}

/* ================= 上传页 ================= */
.dropzones { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 767px) { .dropzones { grid-template-columns: 1fr; } }

.dropzone {
  border: 2px dashed #B6D4F0; border-radius: var(--radius);
  background: var(--blue-light);
  padding: 30px 18px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover { border-color: var(--blue); }
.dropzone.dragover { border-color: var(--blue); background: #BBDEFB; }
.dropzone.has-file { border-color: var(--green); background: var(--green-light); cursor: default; }
.dropzone.has-error { border-color: var(--red); background: var(--red-light); cursor: default; }
.dropzone .dz-emoji { font-size: 2.4rem; display: block; margin-bottom: 6px; }
.dropzone .dz-title { font-weight: 600; font-size: 1rem; }
.dropzone .dz-hint { color: var(--text-2); font-size: .8rem; margin-top: 4px; }
.dropzone .dz-file { margin-top: 10px; font-size: .85rem; color: var(--text); word-break: break-all; }
.dropzone .dz-file b { display: block; }
.dropzone .dz-file span { color: var(--text-2); font-size: .8rem; }
.dropzone .dz-error { margin-top: 8px; color: var(--red); font-size: .82rem; word-break: break-all; }
.dropzone .dz-reload { margin-top: 8px; }

/* KPI 摘要 */
.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px; margin: 14px 0;
}
.kpi {
  background: var(--card); border-radius: 12px; box-shadow: var(--shadow);
  padding: 12px 14px;
}
.kpi .kpi-num { font-size: 1.2rem; font-weight: 700; white-space: nowrap; }
.kpi .kpi-num.ok { color: var(--green); }
.kpi .kpi-num.bad { color: var(--red); }
.kpi .kpi-label { font-size: .74rem; color: var(--text-2); margin-top: 2px; }

/* 警告条 */
.warn-box {
  background: var(--orange-light); border: 1px solid #FFD6A5;
  border-radius: 10px; padding: 10px 14px; margin: 12px 0;
  color: #8D5B00; font-size: .85rem; line-height: 1.7; word-break: break-all;
}

/* ================= 结果页 ================= */
.batch-head { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.batch-head .bh-info { min-width: 0; }
.batch-head .bh-info h2 { font-size: 1.15rem; }
.batch-head .bh-info .bh-sub { color: var(--text-2); font-size: .82rem; margin-top: 2px; word-break: break-all; }
.dl-btns { display: flex; flex-wrap: wrap; gap: 8px; }

/* segmented tab */
.seg { display: flex; gap: 4px; background: #EEF1F5; border-radius: 11px; padding: 4px; margin: 6px 0 12px; overflow-x: auto; }
.seg-btn {
  padding: 8px 16px; border-radius: 8px; white-space: nowrap;
  color: var(--text-2); font-size: .9rem; font-weight: 500;
}
.seg-btn.active { background: #fff; color: var(--blue-dark); font-weight: 600; box-shadow: var(--shadow); }
.seg-btn .cnt { font-size: .72rem; color: var(--red); font-weight: 700; margin-left: 3px; }

/* 工具条 */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
.toolbar .tb-search { max-width: 240px; flex: 1; }
.toolbar .tb-search input { padding: 8px 12px; font-size: .9rem; }
.toolbar label.tb-check { display: flex; align-items: center; gap: 6px; font-size: .88rem; color: var(--text-2); cursor: pointer; user-select: none; }
.toolbar label.tb-check input { width: auto; }

/* 大表格 */
.table-wrap {
  overflow: auto; max-height: calc(100vh - 300px); min-height: 200px;
  background: var(--card); border-radius: 12px; box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.grid-table { border-collapse: collapse; width: 100%; font-size: .85rem; white-space: nowrap; }
.grid-table th, .grid-table td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; }
.grid-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: #F7F9FB; font-size: .78rem; color: var(--text-2); font-weight: 600;
}
.grid-table tbody tr:hover { background: #F5F9FD; }
.grid-table td.cell-num, .grid-table th.cell-num { text-align: right; font-variant-numeric: tabular-nums; }
.grid-table td.cell-model { font-family: Consolas, Menlo, monospace; font-size: .8rem; }
.grid-table tr.row-diff td { background: var(--red-light); }
.grid-table tr.row-diff:hover td { background: #FADBD8; }
.grid-table tr.row-warn td { background: var(--orange-light); }
.grid-table tr.row-sum td { font-weight: 700; background: #F7F9FB; position: sticky; bottom: 0; }
.grid-table td.cell-empty { color: var(--text-3); }
.grid-table td.cell-bad { color: var(--red); font-weight: 700; }

.tag { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .74rem; font-weight: 600; }
.tag-ok { background: var(--green-light); color: var(--green); }
.tag-bad { background: var(--red-light); color: var(--red); }
.tag-warn { background: var(--orange-light); color: var(--orange); }

/* ================= 历史页 ================= */
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: 12px; box-shadow: var(--shadow);
  padding: 13px 16px; cursor: pointer; transition: transform .05s;
}
.history-item:active { transform: scale(.99); }
.history-item .hi-main { flex: 1; min-width: 0; }
.history-item .hi-title { font-weight: 600; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item .hi-sub { font-size: .76rem; color: var(--text-3); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item .hi-right { text-align: right; flex-shrink: 0; }
.history-item .hi-amount { font-weight: 700; font-size: .92rem; }
.history-item .hi-date { font-size: .72rem; color: var(--text-3); }
.history-item .hi-del { color: var(--text-3); font-size: 1.15rem; padding: 8px; flex-shrink: 0; }
.history-item .hi-del:active { color: var(--red); }

/* 账号行（手机端退出入口） */
.account-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--card); border-radius: 12px; box-shadow: var(--shadow);
  padding: 12px 16px; margin-bottom: 12px;
}
.account-row .ac-mail { color: var(--text-2); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 768px) { .account-row { display: none; } }

/* ================= 弹窗 ================= */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn .15s ease;
}
.modal-sheet {
  background: #fff; width: 100%; max-width: 480px;
  border-radius: 20px 20px 0 0; padding: 20px 18px calc(20px + var(--safe-b));
  max-height: 86vh; max-height: 86dvh; overflow-y: auto;
  animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.modal-sheet h3 { font-size: 1.05rem; margin-bottom: 14px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }

/* ================= Toast ================= */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 20px);
  transform: translateX(-50%) translateY(16px);
  background: rgba(33,33,33,.92); color: #fff;
  padding: 10px 20px; border-radius: 999px; font-size: .88rem;
  opacity: 0; pointer-events: none; transition: all .25s ease;
  z-index: 200; max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (min-width: 768px) { .toast { bottom: 34px; } }
