:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #1a2331;
  --muted: #6b7280;
  --primary: #4a88ed;
  --primary-deep: #6c63ff;
  --ok: #059669;
  --bad: #dc2626;
  --warn: #ff9800;
  --border: #ebeef5;
  --radius: 16px;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
  /* App / 刘海屏顶部安全区，避免报表等按钮点不到 */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --app-top-extra: 0px;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* Capacitor App 内额外下移，躲开状态栏 */
html.capacitor-native {
  --app-top-extra: 28px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-top: calc(var(--safe-top) + var(--app-top-extra));
  padding-bottom: var(--safe-bottom);
}
a { color: var(--primary); }

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 14px 80px;
}
.wrap.wide { max-width: 1100px; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.topbar h1 {
  font-size: 1.15rem;
  margin: 0;
}
.meta { color: var(--muted); font-size: 0.85rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 20px;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.remember-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 14px;
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
}
.remember-row input {
  width: auto;
  margin: 0;
  padding: 0;
}
input, select, textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  margin-bottom: 12px;
  background: #fff;
}
textarea { min-height: 72px; resize: vertical; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 1rem;
  cursor: pointer;
  font-weight: 600;
  transition: filter 140ms ease, transform 140ms ease, background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}
.btn:hover:not(:disabled) { filter: brightness(1.05); }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn-block { width: 100%; display: block; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-bad { background: var(--bad); color: #fff; }
.btn-ghost {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-ghost:hover:not(:disabled) {
  background: #f8fafc;
  filter: none;
}
.item-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 8px;
  align-items: start;
}
.item-row input { margin-bottom: 0; }
.item-row .btn { white-space: nowrap; padding: 12px 16px; }

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.scan-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.scan-panel {
  background: #fff;
  border-radius: 14px;
  width: min(480px, 100%);
  padding: 12px;
}
.scan-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
#qrReader {
  width: 100%;
  min-height: 240px;
  overflow: hidden;
  border-radius: 10px;
  background: #111;
}
#qrReader video {
  width: 100% !important;
  border-radius: 10px;
}
.zxing-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 10px;
  background: #111;
}
.zxing-stage video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border-radius: 10px;
}
.zxing-band {
  position: absolute;
  left: 0;
  right: 0;
  top: 30%;
  height: 40%;
  border-top: 2px solid #22d3ee;
  border-bottom: 2px solid #22d3ee;
  background: rgba(34, 211, 238, 0.08);
  pointer-events: none;
}
.zxing-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8px;
  text-align: center;
  font-size: 12px;
  color: #c5d0dc;
  text-shadow: 0 1px 3px #000;
  pointer-events: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.chip {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.9rem;
  cursor: pointer;
}
.chip.on {
  background: #e8f1fb;
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.treat {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.treat .chip { text-align: center; padding: 10px 4px; }

.list-item {
  border-top: 1px solid var(--border);
  padding: 10px 0;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.92rem;
}
.list-item:first-child { border-top: none; }
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: #eee;
}
.tag.ok { background: #e6f6ec; color: var(--ok); }
.tag.bad { background: #fdecea; color: var(--bad); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #111;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 99;
  display: none;
}
.toast.show { display: block; }

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}
.filters label { margin: 0; }
.filters input, .filters select { margin: 0; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  background: #fff;
}
th, td {
  border: 1px solid var(--border);
  padding: 8px;
  text-align: left;
}
th { background: #f8fafc; }
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.stat {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}
.stat .n { font-size: 1.4rem; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 0.8rem; }

.hidden { display: none !important; }
.nav-links { display: flex; gap: 10px; flex-wrap: wrap; font-size: 0.9rem; }

@media (max-width: 600px) {
  .treat { grid-template-columns: repeat(2, 1fr); }
  .stat-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .btn {
    transition: none;
  }
  .btn:active:not(:disabled) {
    transform: none;
  }
}
