:root {
  color-scheme: light;
  --bg: #f4f7f5;
  --panel: #ffffff;
  --ink: #14221b;
  --muted: #66756d;
  --line: #dbe6df;
  --brand: #11824f;
  --brand-strong: #0b6840;
  --soft: #edf8f1;
  --warn: #a65f00;
  --danger: #b42318;
  --danger-soft: #fef1f1;
  --ok: #126a3a;
  --ok-soft: #e8f9f0;
  --panel-soft: #f8fbf9;
  --soft-2: #eef3ef;
  --line-brand: #cfe5d7;
  --on-brand: #ffffff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

/* ── 深色主题（与后台共用 fs_theme 设置） ── */
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c1410;
  --panel: #13201a;
  --panel-soft: #101b15;
  --ink: #e4efe8;
  --muted: #8aa295;
  --line: #24382e;
  --line-brand: #2c4a3a;
  --brand: #2fb673;
  --brand-strong: #27a065;
  --soft: rgba(18, 130, 79, 0.16);
  --soft-2: #18271f;
  --warn: #f3b04c;
  --danger: #f87171;
  --danger-soft: rgba(239, 68, 68, 0.16);
  --ok: #4ade80;
  --ok-soft: rgba(34, 197, 94, 0.16);
  --on-brand: #062e1d;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.app-shell {
  min-height: 100vh;
}

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
}

.logo {
  width: 132px;
  height: auto;
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

.login-panel h1 {
  font-size: 28px;
  line-height: 1.2;
}

.login-panel p {
  margin-top: 8px;
  color: var(--muted);
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.login-panel label {
  margin-top: 18px;
}

input,
select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
  padding: 9px 12px;
}

input:focus,
select:focus {
  border-color: var(--brand);
  outline: 2px solid rgba(22, 122, 74, 0.16);
}

.primary-button,
.ghost-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 9px 14px;
  text-align: center;
  white-space: nowrap;
}

.primary-button {
  background: var(--brand);
  color: var(--on-brand);
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary-button:hover {
  background: var(--brand-strong);
}

.ghost-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
}

.login-panel .primary-button {
  width: 100%;
  margin-top: 22px;
}

.main-view {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.topbar,
.identity-strip,
.view-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px 26px;
  border: 0;
  /* 与小程序一致的品牌绿渐变，底部为圆形弧线 */
  background: linear-gradient(150deg, #064e30 0%, #0b7a45 55%, #0d9152 100%);
  border-radius: 14px 14px 50% 50% / 14px 14px 30px 30px;
  box-shadow: 0 12px 32px rgba(6, 78, 48, 0.18);
  color: #fff;
}

.topbar h1 {
  color: #fff;
  font-size: 26px;
}

.account-box {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  min-width: 0;
  color: rgba(255, 255, 255, 0.88);
}

#account-name {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-box .ghost-button {
  flex: none;
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.account-box .ghost-button:hover {
  background: rgba(255, 255, 255, 0.22);
}

.password-panel {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.password-panel[hidden] {
  display: none;
}

.password-actions {
  display: flex;
  align-items: end;
  gap: 8px;
}

.identity-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1px;
  margin-top: 14px;
  overflow: hidden;
}

.identity-strip div {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 16px;
  background: var(--panel-soft);
}

.identity-strip span {
  color: var(--muted);
  font-size: 13px;
}

.identity-strip strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.module-nav {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.nav-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  padding: 8px 13px;
  text-align: center;
  white-space: nowrap;
}

.nav-button.active {
  border-color: var(--brand);
  background: var(--soft);
  color: var(--brand-strong);
  font-weight: 700;
}

.content-grid {
  margin-top: 14px;
}

.view-panel {
  padding: 18px;
}

.sampling-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
  padding: 20px;
  border: 1px solid var(--line-brand);
  border-radius: 10px;
  background: var(--panel-soft);
}

.sampling-hero p {
  color: var(--brand-strong);
  font-size: 13px;
  font-weight: 800;
}

.sampling-hero h2 {
  margin-top: 4px;
  font-size: 24px;
  line-height: 1.2;
}

.sampling-auto {
  flex: none;
  min-height: 34px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--panel);
  font-size: 13px;
  font-weight: 750;
}

.sampling-status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.sampling-status-grid div {
  min-width: 0;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.sampling-status-grid span,
.capture-field > span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.sampling-status-grid strong {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  color: var(--ink);
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-head h2 {
  font-size: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

/* 表单网格内的按钮：占满单元格、文字可换行，避免溢出 */
.form-grid .primary-button,
.form-grid .ghost-button {
  width: 100%;
  min-width: 0;
  white-space: normal;
  line-height: 1.3;
}

.sample-create-grid {
  align-items: start;
}

.full-field {
  grid-column: 1 / -1;
}

.form-grid.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
}

.inline-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(80px, 96px);
  gap: 8px;
  min-width: 0;
}

.capture-field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.capture-button,
.location-action {
  display: flex;
  width: 100%;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  text-align: center;
  font-weight: 750;
}

.capture-button {
  background: var(--brand);
  color: var(--on-brand);
  cursor: pointer;
}

.capture-button:hover,
.location-action:hover {
  background: var(--brand-strong);
  color: var(--on-brand);
}

#sample-create-image {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

#sample-create-preview {
  display: block;
  width: 100%;
  height: 190px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--soft-2);
}

.location-action {
  border: 1px solid var(--line-brand);
  background: var(--soft);
  color: var(--brand-strong);
}

.readonly-location {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.readonly-location strong {
  min-width: 0;
  overflow: hidden;
  padding: 11px 12px;
  border-radius: 8px;
  background: var(--soft-2);
  color: var(--ink);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inline-field > * {
  min-width: 0;
}

.inline-field .ghost-button {
  width: 100%;
}

.check-field {
  grid-template-columns: auto 1fr;
  align-items: center;
  min-height: 42px;
  color: var(--ink);
}

.check-field input {
  width: 18px;
  min-height: 18px;
  padding: 0;
}

.action-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}

.action-row .primary-button,
.action-row .ghost-button {
  flex: none;
  max-width: 100%;
}

.action-row .status-line {
  min-width: 0;
  flex: 1;
}

.status-line {
  min-height: 22px;
  color: var(--muted);
  font-size: 14px;
}

.status-line.ok {
  color: var(--ok);
}

.status-line.warn {
  color: var(--warn);
}

.status-line.danger {
  color: var(--danger);
}

.list-panel,
.detail-panel {
  display: grid;
  gap: 10px;
  margin: 14px 0;
}

.list-card,
.detail-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
  padding: 12px;
}

.list-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.list-card-head strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.list-card-head .ghost-button,
.list-card-head .primary-button {
  flex: none;
}

.list-card strong {
  font-size: 15px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.detail-rows {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 14px;
}

.detail-row span:first-child {
  color: var(--muted);
  flex: none;
}

.detail-row span:last-child {
  color: var(--ink);
  font-weight: 600;
  text-align: right;
}

.detail-subhead {
  margin-top: 16px;
  margin-bottom: 8px;
  font-weight: 700;
  color: var(--ink);
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: var(--soft);
}

.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.history-head strong {
  color: var(--ink);
}

.history-head span {
  color: var(--muted);
  font-size: 13px;
}

.history-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
}

.history-item {
  flex: 1;
  min-width: 0;
  color: var(--ink);
  font-size: 14px;
}

.stage-tag {
  flex: none;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--soft-2);
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 700;
}

.result-tag {
  flex: none;
  padding: 2px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.result-negative {
  background: var(--ok-soft);
  color: var(--ok);
}

.result-positive {
  background: var(--danger-soft);
  color: var(--danger);
}

.result-invalid {
  background: var(--danger-soft);
  color: var(--danger);
}

@media (max-width: 760px) {
  .main-view {
    padding: 12px;
  }

  .topbar,
  .account-box,
  .password-actions,
  .panel-head,
  .action-row {
    align-items: stretch;
    flex-direction: column;
  }

  .identity-strip,
  .sampling-status-grid,
  .form-grid,
  .form-grid.compact,
  .meta-grid,
  .readonly-location {
    grid-template-columns: 1fr;
  }

  .inline-field {
    grid-template-columns: 1fr;
  }

  .sampling-hero {
    align-items: stretch;
    flex-direction: column;
  }

  .sampling-auto {
    width: fit-content;
  }

  .account-box {
    width: 100%;
  }

  .account-box .ghost-button {
    width: 100%;
  }
}


/* ════ 2026-06 UI 升级：主题切换 / 台账徽章 / 导出 ════ */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  transition: transform 160ms ease, background 160ms ease;
}
.theme-toggle:active { transform: scale(0.92); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
.theme-toggle.on-hero {
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}
.theme-toggle.on-hero:hover { background: rgba(255, 255, 255, 0.22); }

.panel-head-actions {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}
.result-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.result-chip.result-negative { background: var(--ok-soft); color: var(--ok); }
.result-chip.result-positive { background: var(--danger-soft); color: var(--danger); }
.result-chip.result-invalid { background: var(--soft-2); color: var(--muted); }
.gx-status-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--soft-2);
  color: var(--muted);
}
.gx-status-chip.is-success { background: var(--ok-soft); color: var(--ok); }
.gx-status-chip.is-failed { background: var(--danger-soft); color: var(--danger); }
.list-card {
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.list-card:hover {
  border-color: var(--line-brand);
  box-shadow: 0 6px 18px rgba(6, 78, 48, 0.08);
}
.list-card-time {
  color: var(--muted);
  font-size: 12px;
}
