:root {
  --green: #1f9d72;
  --green-d: #157a58;
  --ink: #1f2a30;
  --muted: #6b7b82;
  --bg: #f3f6f5;
  --card: #ffffff;
  --line: #e6ecea;
  --red: #e5484d;
  --amber: #f2a413;
  --radius: 14px;
  --shadow: 0 4px 18px rgba(20, 60, 50, .08);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  max-width: 560px;
  margin: 0 auto;
  padding-bottom: 78px;
  font-size: 15px;
  line-height: 1.5;
}
/* ---------- header ---------- */
.app-header {
  background: linear-gradient(135deg, var(--green), var(--green-d));
  color: #fff;
  padding: 16px 18px;
  position: sticky; top: 0; z-index: 20;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 30px; }
.title { font-size: 19px; font-weight: 700; letter-spacing: .5px; }
.subtitle { font-size: 12px; opacity: .85; }
/* ---------- views ---------- */
.view { padding: 14px; }
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.card h3 { margin: 0 0 10px; font-size: 16px; }
/* ---------- scan ---------- */
.scan-stage {
  position: relative; border-radius: 12px; overflow: hidden;
  background: #0d1413; aspect-ratio: 4/3; display: flex; align-items: center; justify-content: center;
}
#scanVideo { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame {
  position: absolute; inset: 12% 18%; border: 2px solid rgba(255,255,255,.25);
  border-radius: 12px;
}
.scan-frame .corner { position: absolute; width: 22px; height: 22px; border: 3px solid var(--green); }
.corner.tl { top: -3px; left: -3px; border-right: none; border-bottom: none; border-top-left-radius: 8px; }
.corner.tr { top: -3px; right: -3px; border-left: none; border-bottom: none; border-top-right-radius: 8px; }
.corner.bl { bottom: -3px; left: -3px; border-right: none; border-top: none; border-bottom-left-radius: 8px; }
.corner.br { bottom: -3px; right: -3px; border-left: none; border-top: none; border-bottom-right-radius: 8px; }
.scan-hint {
  position: absolute; bottom: 10px; left: 0; right: 0; text-align: center;
  color: #fff; font-size: 13px; text-shadow: 0 1px 3px #000; padding: 0 12px;
}
.scan-result {
  margin-top: 12px; padding: 12px; border-radius: 10px; background: #eafaf3;
  border: 1px solid #bfe9d6; font-size: 14px; word-break: break-all;
}
.scan-result b { color: var(--green-d); }
/* ---------- buttons ---------- */
.btn {
  border: none; border-radius: 10px; padding: 11px 16px; font-size: 15px; font-weight: 600;
  cursor: pointer; background: #eef3f1; color: var(--ink); transition: .15s;
}
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:active { background: var(--green-d); }
.btn.ghost { background: #f0f3f2; color: var(--muted); }
.btn.danger { background: #fdecec; color: var(--red); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; }
.btn-row .btn { flex: 1; }
.manual-entry { margin-top: 16px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 6px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.tip { font-size: 12.5px; color: var(--muted); background: #fff; border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); }
.tip b { color: var(--green-d); }
/* ---------- search ---------- */
.search-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.search-bar input { flex: 1; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 15px; background: #fff; }
.search-bar select { border: 1px solid var(--line); border-radius: 10px; padding: 0 8px; background: #fff; font-size: 14px; }
.stat-row { display: flex; gap: 8px; margin-bottom: 12px; }
.stat-row .stat { flex: 1; background: #fff; border-radius: 10px; padding: 10px; text-align: center; box-shadow: var(--shadow); }
.stat .num { font-size: 20px; font-weight: 700; }
.stat .lbl { font-size: 11px; color: var(--muted); }
.stat.s-expired .num { color: var(--red); }
.stat.s-near .num { color: var(--amber); }
.stat.s-ok .num { color: var(--green); }
/* ---------- box list ---------- */
.box-list { display: flex; flex-direction: column; gap: 10px; }
.med {
  background: #fff; border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow);
  border-left: 5px solid var(--green); position: relative;
}
.med.near { border-left-color: var(--amber); }
.med.expired { border-left-color: var(--red); }
.med .name { font-size: 16px; font-weight: 700; }
.med .eff { font-size: 13px; color: var(--muted); margin: 3px 0 6px; }
.med .meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: #445; }
.med .meta b { color: var(--ink); }
.med .exp { font-weight: 700; }
.med.expired .exp { color: var(--red); }
.med.near .exp { color: var(--amber); }
.med .badge { position: absolute; top: 12px; right: 12px; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 20px; }
.med.expired .badge { background: #fdecec; color: var(--red); }
.med.near .badge { background: #fff4e0; color: #c9810a; }
.med.ok .badge { background: #eafaf3; color: var(--green-d); }
.med .actions { display: flex; gap: 8px; margin-top: 10px; }
.med .actions .btn { flex: 1; padding: 7px; font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
/* ---------- print opts ---------- */
.print-opts, .print-tools { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.print-tools { flex-direction: row; align-items: center; gap: 16px; }
.opt { font-size: 14px; display: flex; align-items: center; gap: 6px; }
.opt select { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); }
/* ---------- lib / me ---------- */
.lib-list { display: flex; flex-wrap: wrap; gap: 8px; }
.lib-chip { background: #eef3f1; border-radius: 20px; padding: 6px 12px; font-size: 13px; }
.lib-chip b { color: var(--green-d); }
/* ---------- tabbar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 560px; display: flex; background: #fff;
  border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(0,0,0,.06); z-index: 30;
}
.tab {
  flex: 1; border: none; background: none; padding: 9px 0 11px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--muted);
}
.tab span { font-size: 20px; }
.tab.active { color: var(--green); font-weight: 700; }
/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-mask { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.modal-card {
  position: relative; background: #fff; width: 100%; max-width: 560px;
  border-radius: 18px 18px 0 0; padding: 18px; max-height: 92vh; overflow-y: auto;
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.icon-btn { border: none; background: #f0f3f2; width: 32px; height: 32px; border-radius: 50%; font-size: 15px; cursor: pointer; }
.form .field { margin-bottom: 12px; display: flex; flex-direction: column; gap: 5px; }
.form label { font-size: 13px; color: var(--muted); font-weight: 600; }
.form input, .form textarea, .form select {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 15px; font-family: inherit; background: #fff;
}
.form input[readonly] { background: #f6f8f7; color: var(--muted); }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: rgba(20,30,28,.92); color: #fff; padding: 10px 18px; border-radius: 22px;
  font-size: 14px; z-index: 80; box-shadow: var(--shadow); max-width: 90%;
}
.toast[hidden] { display: none; }

/* ============ 打印样式 ============ */
@media print {
  body { max-width: none; padding: 0; background: #fff; }
  .app-header, .tabbar, .view:not(#view-print), .modal, .toast, .card, .tip, .search-bar, .stat-row { display: none !important; }
  #view-print { display: block !important; padding: 0; }
  #printPreview { display: block !important; }
}
/* 标签网格 */
.label-grid { display: grid; gap: 6px; margin-top: 10px; }
.label {
  border: 1px solid #333; border-radius: 6px; padding: 8px 10px; position: relative;
  display: flex; gap: 10px; align-items: center; min-height: 78px; page-break-inside: avoid;
  overflow: hidden;
}
.label .ltext { flex: 1; min-width: 0; }
.label .lname { font-weight: 800; font-size: 15px; line-height: 1.2; }
.label .leff { font-size: 11px; color: #333; margin-top: 3px; }
.label .lexp { font-size: 12px; font-weight: 700; margin-top: 2px; }
.label .lexp.near { color: #b9790a; }
.label .lexp.expired { color: #c0392b; }
.label .lqr { width: 60px; height: 60px; flex: none; }
.label .lqr canvas, .label .lqr img { width: 60px !important; height: 60px !important; }
/* 汇总表 */
.sheet { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 12px; }
.sheet th, .sheet td { border: 1px solid #555; padding: 6px 8px; text-align: left; }
.sheet th { background: #eef3f1; }
.sheet .st-expired { color: #c0392b; font-weight: 700; }
.sheet .st-near { color: #b9790a; font-weight: 700; }
.print-title { font-size: 18px; font-weight: 800; margin: 0 0 4px; }
.print-sub { font-size: 12px; color: #555; margin: 0 0 6px; }
@media screen {
  #printPreview { display: none; }
  #printPreview.show-preview { display: block; }
  #printPreview .label { background: #fff; }
}

/* ---------- 同步状态点 ---------- */
.sync-line { display: flex; align-items: center; gap: 6px; margin-top: 3px; font-size: 11px; opacity: .9; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: #bbb; flex: none; }
.sync-dot.off { background: #cfd8d5; }
.sync-dot.online { background: #2ecc71; }
.sync-dot.offline { background: #e67e22; }
.sync-dot.syncing { background: #3498db; animation: syncPulse 1s infinite; }
@keyframes syncPulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.sync-status { background: #eafaf1; color: #1e8449; border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; font-size: 13px; }
