:root {
  --bg: #eef2ee;
  --paper: #ffffff;
  --ink: #1a231c;
  --muted: #5c6b61;
  --line: #d7e0d8;
  --green: #1b5c3c;
  --green-deep: #143f2b;
  --green-ink: #f3f7f4;
  --red: #b42318;
  --amber: #9a6700;
  --ok: #1b7a45;
  --soft: #e8f1eb;
  --shadow: 0 1px 0 rgba(20, 63, 43, 0.04), 0 8px 24px rgba(20, 63, 43, 0.06);
  --r: 8px;
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--green); text-decoration: none; }
#app { min-height: 100dvh; }
button:active, .chip:active, .stat:active { transform: scale(0.99); }

.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 0 16px;
  background: var(--green-deep); color: var(--green-ink);
}
.brand {
  font-weight: 750; letter-spacing: 0.02em; white-space: nowrap;
  font-size: 15px;
}
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.nav a {
  color: var(--green-ink); padding: 8px 12px; border-radius: 6px;
  min-height: 36px; display: inline-flex; align-items: center;
  opacity: .82; white-space: nowrap; font-size: 14px;
}
.nav a:hover { opacity: 1; background: rgba(255,255,255,.08); }
.nav a.on { background: rgba(255,255,255,.14); opacity: 1; font-weight: 650; }
.roles { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.roles span { font-size: 12px; opacity: .85; white-space: nowrap; }
.roles button {
  border: 1px solid rgba(255,255,255,.28);
  background: transparent; color: var(--green-ink);
  border-radius: 6px; padding: 6px 10px; min-height: 32px; font-size: 13px;
}

.wrap { max-width: 1680px; margin: 0 auto; padding: 20px 24px 128px; }
.page-head { margin: 0 0 16px; }
.page-head h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.filter-bar {
  display: grid;
  grid-template-columns: minmax(200px, 1.6fr) minmax(180px, 1.2fr) minmax(160px, 0.9fr) auto;
  gap: 10px 12px;
  align-items: end;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px 16px;
  margin: 0 0 16px;
  box-shadow: var(--shadow);
}
.filter-bar label { margin: 0; }
.filter-bar input, .filter-bar select { width: 100%; min-height: 44px; }
.filter-actions { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.filter-bar .btn-go, .filter-bar .btn-ghost {
  min-height: 44px; height: 44px; width: auto; min-width: 88px;
  padding: 0 16px; margin: 0; font-size: 14px;
}
#stats-form.filter-bar {
  grid-template-columns: repeat(4, minmax(140px, 1fr)) auto;
}

.action-duo {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin: 0 0 16px;
}
.action-duo .primary, .action-duo .btn-ghost {
  width: 100%; margin: 0; min-height: 52px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px 14px;
  align-items: end;
}

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 12px;
}
.card-head h2 { margin: 0; }

.add-form {
  margin-top: 14px; padding-top: 14px;
  border-top: 1px solid var(--line);
}
.add-form .btn-go { min-height: 48px; width: 100%; }
.grid-3 .span-all { grid-column: 1 / -1; }

.tabs {
  display: flex; gap: 4px; flex-wrap: wrap;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--r); padding: 4px; margin: 0 0 14px;
  width: fit-content; max-width: 100%;
}
.tabs a {
  padding: 8px 16px; border-radius: 6px; color: var(--muted);
  font-size: 14px; font-weight: 650; min-height: 36px;
  display: inline-flex; align-items: center;
}
.tabs a.on { background: var(--green); color: #fff; }
.tabs a:hover { background: var(--soft); color: var(--ink); }
.tabs a.on:hover { background: var(--green-deep); color: #fff; }

.file-btn {
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--r);
  background: #fff; cursor: pointer; font-weight: 650; font-size: 14px;
}
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.home-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.hit-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-top: 8px; }
.sec { font-size: 14px; margin: 18px 0 8px; color: var(--muted); font-weight: 650; }
.stat {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r);
  padding: 14px 16px; box-shadow: var(--shadow); text-align: left; width: 100%;
}
.stat:hover { border-color: #b7cbbd; }
.stat b { display: block; font-variant-numeric: tabular-nums; font-size: 26px; line-height: 1.15; }
.stat span { color: var(--muted); font-size: 12px; }
.queue {
  margin-top: 14px; background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--r); overflow: hidden;
}
.queue-row {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; width: 100%;
  padding: 12px 16px; border: 0; background: transparent; text-align: left;
  border-bottom: 1px solid var(--line); min-height: 52px;
}
.queue-row:last-child { border-bottom: 0; }
.queue-row:hover { background: var(--soft); }
.queue-row .n { font-weight: 750; font-variant-numeric: tabular-nums; min-width: 2ch; }
.queue-row .t { flex: 1; min-width: 180px; }
.queue-row .go { color: var(--green); font-size: 13px; font-weight: 650; }
.queue-row .fails { width: 100%; display: flex; flex-wrap: wrap; gap: 6px; padding-left: 18px; }

.primary {
  display: block; width: 100%; margin-top: 14px;
  background: var(--green); color: var(--green-ink); border: 0;
  border-radius: var(--r); min-height: 52px; font-size: 17px; font-weight: 700;
}
.primary:hover { background: var(--green-deep); }
.sub-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }

.card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px 18px; margin-bottom: 12px; box-shadow: var(--shadow);
  overflow: hidden;
}
.card h2 { margin: 0 0 12px; font-size: 15px; }
.hint {
  font-size: 12px; color: var(--muted); background: var(--soft);
  border-radius: 6px; padding: 8px 10px; margin: 0 0 12px;
  display: flex; gap: 12px; flex-wrap: wrap;
}
.req { color: var(--red); }
.required-row { grid-template-columns: 1fr; }
@media (min-width: 800px) {
  .required-row { grid-template-columns: 1fr 1fr 1fr; }
}

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 12px; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 6px;
  padding: 8px 12px; min-height: 40px; font-size: 14px;
}
.chip.on { background: var(--green); color: var(--green-ink); border-color: var(--green); }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; min-width: 0; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 550; min-width: 0; }
input, select, textarea {
  border: 1px solid var(--line); border-radius: 6px; background: #fff;
  padding: 11px 12px; min-height: 48px; font-size: 16px;
  font-variant-numeric: tabular-nums;
  width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid #1b5c3c55; border-color: var(--green);
}
textarea { min-height: 76px; font-size: 15px; }
.weigh input { font-size: 28px; min-height: 64px; font-weight: 700; min-width: 0; }
.sensory { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.live {
  border-radius: var(--r); padding: 14px 16px; margin: 12px 0 0;
  background: var(--soft); border: 1px solid #c5d8cb;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 14px;
  font-variant-numeric: tabular-nums;
}
.live.bad { background: #fdecea; border-color: #f0c4bf; }
.live .k { font-size: 12px; color: var(--muted); }
.live .v { font-size: 22px; font-weight: 750; line-height: 1.15; }
.live .v.red { color: var(--red); }
.live .v.ok { color: var(--ok); }

.dock {
  position: sticky; bottom: 0; z-index: 15;
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(238, 242, 238, .94); border-top: 1px solid var(--line);
}
.dock .ghost, .btn-ghost {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r);
  min-height: 52px; font-size: 16px; font-weight: 650; color: var(--ink);
}
.dock .go, .btn-go {
  background: var(--green); color: #fff; border: 0; border-radius: var(--r);
  min-height: 52px; font-size: 16px; font-weight: 700;
}
.dock .go.warn { background: var(--red); }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--paper); }
.table { width: 100%; min-width: 1480px; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.table.compact { min-width: 0; }
.table th, .table td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; background: #f5f8f5; position: sticky; top: 0; z-index: 1; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: var(--soft); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.wrap-cell {
  white-space: normal;
  min-width: 280px;
  max-width: 420px;
  line-height: 1.45;
}
.table td.wrap-cell .fail-chip { display: block; margin: 0 0 6px; width: fit-content; max-width: 100%; }
.table td.wrap-cell .fail-chip:last-child { margin-bottom: 0; }
.stripe { width: 6px; border-radius: 99px; display: inline-block; height: 22px; vertical-align: middle; margin-right: 8px; }
.stripe.ok { background: var(--ok); }
.stripe.wait { background: var(--amber); }
.stripe.bad { background: var(--red); }
.stripe.mute { background: #9aa59d; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 12px; background: var(--soft); color: var(--ink);
}
.badge.prod { background: var(--green); color: #fff; }
.badge.qc { background: #efe8d6; }
.badge.fail { background: #fdecea; color: var(--red); }
.badge.ok { background: var(--soft); color: var(--ok); }

.compare {
  display: grid; grid-template-columns: 1fr 1fr 1fr 0.9fr;
  gap: 0; overflow: auto; border: 1px solid var(--line); border-radius: var(--r);
}
.compare div { padding: 10px 12px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.compare .h { color: var(--muted); font-size: 12px; background: #f5f8f5; font-weight: 650; }
.lossbar {
  margin-top: 12px; padding: 14px 16px; border-radius: var(--r);
  background: var(--green-deep); color: var(--green-ink);
  display: flex; gap: 28px; flex-wrap: wrap;
}
.lossbar b { font-size: 22px; font-variant-numeric: tabular-nums; display: block; }
.money { color: var(--red); font-weight: 700; }
.search-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.search-bar input, .search-bar select { min-height: 44px; flex: 1; min-width: 140px; }
.search-bar .btn-go, .search-bar .btn-ghost { min-height: 44px; padding: 0 14px; width: auto; }
.cell-f { border: 0; background: none; padding: 0; color: var(--green); font-weight: 650; min-height: auto; text-align: left; }
.tiny { font-size: 11px; color: var(--red); white-space: normal; max-width: 280px; margin-top: 4px; }
.bad-field { color: var(--red); }
.bad-field input { border-color: var(--red); background: #fdecea; }
.fail-box { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.fail-chip {
  display: inline-block; background: #fdecea; color: var(--red);
  border: 1px solid #f0c4bf; border-radius: 4px; padding: 4px 8px;
  font-size: 12px; font-weight: 650; white-space: normal;
}
.water-pair { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag-qc, .tag-prod {
  display: inline-block; border-radius: 4px; padding: 3px 8px;
  font-size: 12px; font-weight: 650; font-variant-numeric: tabular-nums;
}
.tag-qc { color: #6b7280; background: #eef0ee; }
.tag-prod { color: #166534; background: #dcfce7; }
.cell-qc { color: #6b7280; }
.cell-prod { color: #166534; font-weight: 700; }

.auth {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1200px 400px at 50% -10%, #2a7a52 0%, transparent 55%),
    var(--green-deep);
}
.auth-card {
  width: min(400px, 100%); background: #fff; border-radius: 10px;
  padding: 28px 24px; box-shadow: 0 20px 50px rgba(0,0,0,.18);
  display: flex; flex-direction: column; gap: 12px;
}
.auth-card .mark { font-size: 12px; color: var(--muted); letter-spacing: 0.12em; }
.auth-card h1 { margin: 0; color: var(--green-deep); font-size: 22px; }
.auth-card .lead { margin: 0; color: var(--muted); font-size: 14px; }
.error { color: var(--red); margin: 0; font-size: 13px; }

@media (max-width: 1100px) {
  .filter-bar, #stats-form.filter-bar { grid-template-columns: 1fr 1fr 1fr; }
  .filter-actions { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
  .home-grid { grid-template-columns: 1fr 1fr; }
  .hit-grid { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .row, .sensory, .live, .grid-3 { grid-template-columns: 1fr 1fr; }
  .compare { grid-template-columns: 1fr 1fr; }
  .wrap { padding: 16px 12px 140px; }
  .top { flex-wrap: wrap; min-height: auto; padding: 8px 12px; }
  .nav { display: flex; width: 100%; order: 3; }
  .filter-bar, #stats-form.filter-bar { grid-template-columns: 1fr; padding: 12px; }
  .action-duo { grid-template-columns: 1fr; }
  .tabs { width: 100%; }
}
@media (max-width: 560px) {
  .row, .row.weigh, .sensory, .live, .grid-3 { grid-template-columns: 1fr; }
  .weigh input { font-size: 22px; }
}
