:root {
  --blue: #2563eb;
  --blue-d: #1d4ed8;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --green: #16a34a;
  --red: #dc2626;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}
.app-header {
  background: var(--blue);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 0;
  position: sticky; top: 0; z-index: 10;
}
.app-header h1 { margin: 0 0 10px; font-size: 20px; }
.tabs { display: flex; gap: 4px; }
.tab {
  flex: 1; padding: 10px 4px; border: none; background: transparent;
  color: rgba(255,255,255,.7); font-size: 14px; cursor: pointer;
  border-bottom: 3px solid transparent;
}
.tab.active { color: #fff; border-bottom-color: #fff; font-weight: 600; }
main { padding: 16px; max-width: 900px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
.card {
  background: var(--card); border-radius: 12px; padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08); margin-bottom: 16px;
}
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input[type=text], .field input[type=password], .field input[type=number], .field input[type=date],
.field select, .filter-row input, .filter-row select {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 16px; background: #fff;
}
/* 日期输入 + 「回到今天」快捷按钮同一行 */
.date-row { display: flex; gap: 8px; align-items: stretch; }
.date-row input[type=date] { flex: 1 1 auto; min-width: 0; }
.date-row .btn { flex: 0 0 auto; white-space: nowrap; }
.switch-row { display: flex; align-items: center; justify-content: space-between; }
.switch-row label { margin: 0; font-size: 15px; color: var(--text); }
.switch-row input[type=checkbox] { width: 44px; height: 26px; accent-color: var(--blue); }
.hidden { display: none; }
.actions { display: flex; gap: 10px; margin-top: 8px; }
.btn {
  padding: 11px 18px; border: 1px solid var(--border); background: #fff;
  border-radius: 8px; font-size: 15px; cursor: pointer; color: var(--text);
}
.btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn.primary:active { background: var(--blue-d); }
/* 键盘焦点可见性(仅键盘导航时显示,不影响鼠标点击) */
.chip:focus-visible, .btn:focus-visible, .row-actions button:focus-visible {
  outline: 2px solid var(--blue); outline-offset: 2px;
}
.filter-row { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filter-row > * { flex: 1; min-width: 100px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* 窄屏「左右滑动查看」提示:用 ::before 直接挂在 .table-wrap 上,
   无需改 HTML,记录列表与统计表格的所有表格都会显示,仅小屏出现。 */
@media (max-width: 640px) {
  .table-wrap::before {
    content: "← 左右滑动查看 →";
    display: block; font-size: 12px; color: var(--muted);
    text-align: right; padding: 0 2px 4px;
  }
}
table { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
th, td { padding: 9px 8px; text-align: right; border-bottom: 1px solid var(--border); }
th:first-child, td:first-child,
#records-table th:nth-child(2), #records-table td:nth-child(2) { text-align: left; }
th { color: var(--muted); font-weight: 600; }
table.matrix td.sum { font-weight: 600; color: var(--blue); }
table.matrix tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: none; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.preset-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  padding: 7px 14px; border: 1px solid var(--border); background: #fff;
  border-radius: 16px; font-size: 14px; cursor: pointer; color: var(--text);
}
.chip.active { background: var(--blue); color: #fff; border-color: var(--blue); }
#stats-custom { margin-bottom: 8px; }
.range-label { font-size: 13px; color: var(--muted); }
.day-mark { color: var(--blue); font-weight: 700; margin-left: 2px; }
.table-note { font-size: 12px; color: var(--muted); margin-top: 10px; }
.field.no-margin { margin-bottom: 0; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.hint:empty { display: none; }
.tag {
  font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: 10px;
  background: #fee2e2; color: var(--red); margin-left: 6px; vertical-align: middle;
}
.tag.ok { background: #dcfce7; color: var(--green); }
.btn.danger { color: var(--red); border-color: #fecaca; }
.day-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-bottom: 12px; }
.day-summary .k { display: block; font-size: 12px; color: var(--muted); }
.day-summary .v { display: block; font-size: 17px; font-weight: 700; margin-top: 2px; }
.day-records { list-style: none; padding: 0; margin: 0; }
.day-records li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 2px; border-top: 1px solid var(--border); font-size: 14px; }
.day-records .meta { color: var(--muted); font-size: 13px; margin-left: 4px; }
.muted { color: #94a3b8; }
.small { font-size: 13px; }
td.empty-cell { text-align: center !important; color: #94a3b8; }
.warn { background: #fef3c7; color: #92400e; border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-bottom: 16px; }
.warn > div + div { margin-top: 6px; }
.tag.warn-tag { background: #fef3c7; color: #92400e; }
.live { font-size: 13px; color: var(--blue); font-weight: 600; margin-top: 6px; }
.live:empty { display: none; }
details.precise { border: 1px dashed var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
details.precise summary { cursor: pointer; font-size: 14px; color: var(--blue); }
details.precise[open] summary { margin-bottom: 12px; }
details.precise .field:last-child { margin-bottom: 0; }
.gap-box { background: #fef3c7; border-radius: 8px; padding: 12px; margin-bottom: 14px; font-size: 14px; color: #78350f; }
.gap-q { font-weight: 600; margin-bottom: 8px; }
.radio { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; cursor: pointer; line-height: 1.4; }
.radio input { margin-top: 3px; flex-shrink: 0; }
.day-issue { background: #fef3c7; color: #92400e; border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-bottom: 10px; }
.issue-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.btn.sm { padding: 6px 12px; font-size: 13px; }
#day-calc { margin: 0 0 10px; }
.est {
  display: inline-block; font-size: 11px; line-height: 1; padding: 2px 4px; margin-left: 3px;
  border-radius: 4px; background: #ffedd5; color: #c2410c; vertical-align: middle; font-weight: 500;
}
.stat-card .k .sub { font-size: 12px; color: #94a3b8; }
.type-idle { color: var(--muted); }
.type-open, .type-missing { color: #b45309; }
.scroll-y { max-height: 360px; overflow-y: auto; }
/* 当天里程单价表纵向滚动时表头吸顶 */
.scroll-y thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--card);
  box-shadow: inset 0 -1px 0 var(--border);
}
/* 看板「统计周期」切换:只显示选中周期的卡片 */
.period-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.period-label { font-size: 13px; color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--blue); border-radius: 8px; overflow: hidden; }
.seg .chip { border: none; border-radius: 0; padding: 7px 18px; }
.seg .chip + .chip { border-left: 1px solid var(--blue); }
#view-stats[data-show="month"] .card[data-period]:not([data-period="month"]),
#view-stats[data-show="quarter"] .card[data-period]:not([data-period="quarter"]),
#view-stats[data-show="year"] .card[data-period]:not([data-period="year"]) { display: none; }
.cell-sub { font-size: 11px; color: #94a3b8; font-weight: 400; margin-top: 2px; }
table.matrix td.best { color: var(--green); font-weight: 700; }
table.matrix td.best .cell-sub, table.matrix td.sum .cell-sub { font-weight: 400; }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card { background: var(--card); border-radius: 12px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.stat-card .v { font-size: 24px; font-weight: 700; color: var(--blue); }
.stat-card .k { font-size: 13px; color: var(--muted); margin-top: 4px; }
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.bar-row .label { width: 90px; color: var(--muted); flex-shrink: 0; }
.bar-row .track { flex: 1; background: var(--bg); border-radius: 6px; height: 20px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--blue); border-radius: 6px; }
.bar-row .val { width: 80px; text-align: right; font-variant-numeric: tabular-nums; }
.platform-list { list-style: none; padding: 0; margin: 0; }
.platform-list li { display: flex; align-items: center; justify-content: space-between; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.platform-list .badge { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: #dcfce7; color: var(--green); }
.platform-list .badge.off { background: #fee2e2; color: var(--red); }
.row-actions { display: flex; gap: 6px; }
.row-actions button { padding: 5px 10px; font-size: 12px; border-radius: 6px; border: 1px solid var(--border); background: #fff; cursor: pointer; }
.row-actions .del { color: var(--red); border-color: #fecaca; }
.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(100px);
  background: #0f172a; color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: 14px; opacity: 0; transition: all .3s; z-index: 100; max-width: 90%;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
/* 可点击的提示(如「有新版本」),给出可操作的外观 */
.toast.toast-action { cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
/* 首屏加载占位:纯 CSS,JS 执行前就显示,不依赖任何脚本 */
#boot-loading {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: var(--bg); color: var(--muted); font-size: 15px;
}
.boot-spinner {
  width: 28px; height: 28px; border: 3px solid var(--border);
  border-top-color: var(--blue); border-radius: 50%;
  animation: boot-spin .8s linear infinite;
}
@keyframes boot-spin { to { transform: rotate(360deg); } }
/* 登录页 */
body.locked .app-header, body.locked main { display: none; }
.auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 24px) 16px calc(env(safe-area-inset-bottom) + 24px);
}
.auth-screen.hidden { display: none; }
.auth-card { background: var(--card); border-radius: 14px; box-shadow: 0 4px 20px rgba(0,0,0,.08); padding: 24px 20px; width: 100%; max-width: 360px; }
.auth-card h1 { margin: 0 0 18px; font-size: 20px; text-align: center; color: var(--blue); }
.auth-card p.hint { margin: 0 0 14px; line-height: 1.5; }
.auth-card code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 12px; word-break: break-all; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; }
.auth-msg { font-size: 13px; color: var(--red); margin-top: 12px; min-height: 18px; text-align: center; }
/* ---------- 3.3.0:逐单录入 ---------- */
.form-hint { margin: -6px 0 12px; }
.hint.err { color: var(--red); }
/* 当天逐单列表:正在修改的那一条高亮 */
.day-records li.editing { background: #eff6ff; border-radius: 6px; padding-left: 6px; padding-right: 6px; }
.day-records .idx { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 2px; }
.mini-tag {
  display: inline-block; font-size: 11px; line-height: 1; padding: 2px 5px; margin-left: 4px;
  border-radius: 4px; background: var(--bg); color: var(--muted); vertical-align: middle; font-weight: 500;
}
/* ---------- 3.3.0:数据导入 / 导出 ---------- */
.card h4 { margin: 18px 0 10px; font-size: 14px; }
.field input[type=file] {
  width: 100%; padding: 10px; border: 1px dashed var(--border); border-radius: 8px;
  background: #fff; font-size: 14px;
}
.field input[type=file]:focus-visible, .io-table input[type=checkbox]:focus-visible {
  outline: 2px solid var(--blue); outline-offset: 2px;
}
.io-summary { font-size: 13px; line-height: 1.6; margin-bottom: 10px; }
.io-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.io-pill { padding: 2px 10px; border-radius: 10px; background: var(--bg); color: var(--muted); font-size: 12px; }
.io-pill.new { background: #dcfce7; color: var(--green); }
.io-pill.err { background: #fee2e2; color: var(--red); }
.io-pill.warn-p { background: #fef3c7; color: #92400e; }
.io-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.io-tools .hint { margin-top: 0; }
.io-wrap { max-height: 420px; }
table.io-table th.l, table.io-table td.l { text-align: left; }
table.io-table td:first-child, table.io-table th:first-child { text-align: center; }
table.io-table input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--blue); cursor: pointer; }
table.io-table input[type=checkbox]:disabled { cursor: not-allowed; }
table.io-table tr.io-warning td { background: #fef3c7; }
table.io-table tr.io-duplicate td, table.io-table tr.io-error td { color: #94a3b8; }
table.io-table tr.io-error td.st { color: var(--red); font-weight: 600; }
table.io-table tr.io-new td.st { color: var(--green); font-weight: 600; }
table.io-table td.msg { white-space: normal; min-width: 200px; max-width: 360px; }
.io-result { background: #f0fdf4; color: #14532d; border-radius: 8px; padding: 10px 12px; font-size: 13px; margin: 12px 0 4px; }
.io-result.has-fail { background: #fef3c7; color: #92400e; }
.io-result ul { margin: 6px 0 0; padding-left: 18px; max-height: 200px; overflow-y: auto; }
.io-export-row { align-items: flex-end; }
.io-date { display: block; }
.io-date span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.io-export-row .btn { flex: 0 0 auto; }
