:root {
  /* 更现代的色板 */
  --bg: #f5f7fb;
  --bg-soft: #eef2f8;
  --panel: #ffffff;
  --border: #e4e7eb;
  --border-soft: #eef0f3;
  --text: #1a2233;
  --text-soft: #3a4252;
  --muted: #6b7685;
  --muted-soft: #9aa5b1;
  --primary: #3b6ff6;
  --primary-dark: #1d4ed8;
  --primary-soft: #eaf0ff;
  --primary-softer: #f3f7ff;
  --good: #16a34a;
  --good-soft: #e6f4ec;
  --warn: #d97706;
  --warn-soft: #fef3e6;
  --neg: #dc2626;
  --neg-soft: #fee2e2;
  --pos: #16a34a;
  --shadow-xs: 0 1px 2px rgba(20,30,50,.04);
  --shadow-sm: 0 2px 6px rgba(20,30,50,.06);
  --shadow-md: 0 4px 12px rgba(20,30,50,.08);
  --shadow-lg: 0 12px 32px rgba(20,30,50,.16);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* 桌面访问时居中限宽，更像手机 */
  max-width: 640px;
  margin: 0 auto;
  box-shadow: 0 0 40px rgba(20,30,50,.08);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ===== topbar ===== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  background: linear-gradient(180deg, #fff 0%, #fafbfd 100%);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky; top: 0; z-index: 10;
  padding-top: max(14px, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: -.2px; }
.brand .logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), #6b8fff);
  color: #fff; font-weight: 800; font-size: 15px;
  box-shadow: 0 2px 8px rgba(59,111,246,.35);
}
.actions { display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 9px 16px; border-radius: var(--radius-sm); cursor: pointer; font-size: 14px;
  transition: all .18s; line-height: 1.2; min-height: 40px; font-weight: 500;
}
.btn:hover { background: var(--bg-soft); border-color: var(--muted-soft); }
.btn:active { transform: scale(.97); }
.btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; border-color: transparent;
  box-shadow: 0 2px 8px rgba(59,111,246,.3);
}
.btn.primary:hover { box-shadow: 0 4px 14px rgba(59,111,246,.45); transform: translateY(-1px); }
.btn.primary:active { transform: scale(.97); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); font-size: 20px; padding: 9px 12px; min-width: 40px; }
.btn.ghost:hover { background: var(--bg-soft); color: var(--text); }
.btn.block { width: 100%; }

/* ===== tabs ===== */
.tabs {
  display: flex; flex-shrink: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 60px; z-index: 9;
}
.tab {
  flex: 1; padding: 14px 8px; border: none; background: transparent;
  color: var(--muted); font-size: 14px; cursor: pointer;
  border-bottom: 2px solid transparent; transition: all .2s;
  position: relative; font-weight: 500;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab.active::after {
  content: ''; position: absolute; bottom: -1px; left: 50%; transform: translateX(-50%);
  width: 24px; height: 3px; background: var(--primary); border-radius: 2px 2px 0 0;
}
.badge {
  display: inline-block; min-width: 20px; padding: 2px 8px; margin-left: 5px;
  background: var(--primary-soft); color: var(--primary);
  border-radius: 10px; font-size: 11px; font-weight: 700;
}
.tab.active .badge { background: var(--primary); color: #fff; }

/* ===== content / pages ===== */
.content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.page { display: none; padding: 14px; animation: fadeIn .25s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ===== add toggle ===== */
.add-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; margin-bottom: 12px;
  background: linear-gradient(135deg, var(--primary), #5b85f7);
  color: #fff;
  border-radius: var(--radius); cursor: pointer; font-weight: 600; font-size: 15px;
  box-shadow: 0 4px 12px rgba(59,111,246,.28);
  transition: all .2s;
}
.add-toggle:active { transform: scale(.98); }
.add-toggle .caret { font-size: 12px; transition: transform .25s; opacity: .8; }
.add-toggle.open .caret { transform: rotate(180deg); }

/* ===== card ===== */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; padding: 14px 16px 8px; }
.card-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.card-head .hint { color: var(--muted); font-size: 12px; }

/* ===== form ===== */
.add-form { padding: 4px 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 7px; font-size: 13px; color: var(--muted); font-weight: 500; }
.field input, .field select {
  padding: 11px 14px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 15px; color: var(--text); background: #fff;
  transition: all .18s; min-height: 44px;
  width: 100%; box-sizing: border-box;
}
/* 隐藏 number input 的 spinner 按钮，避免宽度不一 */
.field input[type="number"]::-webkit-outer-spin-button,
.field input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none; margin: 0;
}
.field input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.field input::placeholder { color: var(--muted-soft); }
.field input:focus, .field select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
  background: #fff;
}
.field small { font-size: 11px; color: var(--muted-soft); }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; min-width: 0; }

.platform-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 8px 14px; border: 1.5px solid var(--border);
  border-radius: 20px; font-size: 13px; cursor: pointer;
  background: #fff; color: var(--muted); user-select: none;
  transition: all .18s; min-height: 36px; font-weight: 500;
}
.chip:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-softer); }
.chip.on {
  background: linear-gradient(135deg, var(--primary-soft), #f0f6ff);
  border-color: var(--primary); color: var(--primary-dark); font-weight: 600;
  box-shadow: 0 1px 4px rgba(59,111,246,.18);
}

/* ===== list toolbar ===== */
.list-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px 6px;
}
.select-all {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px; color: var(--muted); cursor: pointer; user-select: none; font-weight: 500;
}
.select-all input { margin: 0; cursor: pointer; width: 18px; height: 18px; accent-color: var(--primary); }
.btn-mini {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 6px 12px; border-radius: 7px; cursor: pointer; font-size: 13px;
  line-height: 1.4; transition: all .15s; min-height: 32px; font-weight: 500;
}
.btn-mini.danger { color: var(--neg); border-color: #f5b0b0; background: var(--neg-soft); }
.btn-mini.danger:hover { background: #fee; border-color: var(--neg); }
.btn-mini:active { transform: scale(.96); }
.list-toolbar .hint { margin-left: auto; }

/* ===== product list ===== */
.list-card { margin-top: 12px; }
.product-list { padding: 4px 12px 14px; }
.empty {
  text-align: center; color: var(--muted-soft); padding: 32px 20px;
  font-size: 14px; line-height: 1.6;
}

.product-item {
  position: relative;
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px; border-radius: var(--radius-sm); margin-bottom: 8px;
  border: 1.5px solid var(--border-soft); background: #fff;
  cursor: pointer; transition: all .2s;
  box-shadow: var(--shadow-xs);
}
.product-item:hover { border-color: var(--primary); background: #fcfdff; box-shadow: var(--shadow-sm); }
.product-item:active { background: var(--primary-softer); }
.product-item.active {
  border-color: var(--primary); background: var(--primary-soft);
  box-shadow: 0 0 0 1px var(--primary), var(--shadow-sm);
}
.product-item.selected { border-color: var(--primary); background: var(--primary-soft); }
.item-check { flex: 0 0 auto; display: flex; align-items: center; margin-top: 5px; cursor: pointer; }
.item-check input { margin: 0; cursor: pointer; width: 19px; height: 19px; accent-color: var(--primary); }
.item-body { flex: 1; min-width: 0; }
.product-item .row1 { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.product-item .name {
  font-weight: 700; font-size: 15px; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text);
}
.tag {
  display: inline-block; padding: 3px 9px; border-radius: 5px;
  font-size: 10px; font-weight: 700; letter-spacing: .8px;
}
.tag.rx { background: var(--warn-soft); color: var(--warn); }
.tag.otc { background: var(--good-soft); color: var(--good); }
.product-item .row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 14px;
  font-size: 12px; color: var(--muted); font-weight: 500;
}
.product-item .row2 b { color: var(--text); font-weight: 700; margin-left: 2px; }
.product-item .row3 {
  margin-top: 8px; font-size: 12px; color: var(--muted);
  padding: 8px 36px 4px 0; border-top: 1px dashed var(--border-soft); line-height: 1.6;
}
.product-item .row3 b { color: var(--primary); font-weight: 700; }
.product-item .row3.warn b { color: var(--warn); }
.product-item .row3.muted b { color: var(--neg); }
.product-item .delete {
  position: absolute; bottom: 10px; right: 10px;
  width: 28px; height: 28px; border: none; background: transparent;
  color: var(--muted-soft); cursor: pointer; border-radius: 7px;
  font-size: 20px; line-height: 1; opacity: 0; transition: all .18s;
  display: flex; align-items: center; justify-content: center;
}
.product-item:hover .delete, .product-item .delete:active { opacity: 1; }
.product-item .delete:hover { background: var(--neg-soft); color: var(--neg); }

/* ===== detail ===== */
.empty-detail {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 55vh; color: var(--muted-soft); padding: 48px 24px; text-align: center;
}
.empty-detail .empty-icon {
  font-size: 64px; margin-bottom: 16px; opacity: .4;
  filter: grayscale(.3);
}

.detail-content { display: flex; flex-direction: column; gap: 14px; }

.product-info {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: linear-gradient(180deg, #fff 0%, var(--primary-softer) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.product-info .pi-name {
  font-size: 17px; font-weight: 800; flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px; letter-spacing: -.3px;
}
.product-info .pi-sep { width: 1px; height: 24px; background: var(--border); }
.product-info .pi-item { font-size: 12px; color: var(--muted); font-weight: 500; }
.product-info .pi-item b { color: var(--text); font-size: 15px; font-weight: 700; margin-left: 4px; }

.recommend-bar { display: flex; gap: 10px; flex-wrap: wrap; }
.rec-card {
  flex: 1; min-width: 140px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow-sm); transition: all .2s;
  position: relative; overflow: hidden;
}
.rec-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.rec-card.primary {
  background: linear-gradient(135deg, var(--primary) 0%, #5b8fff 100%);
  border-color: transparent; color: #fff;
  box-shadow: 0 4px 14px rgba(59,111,246,.35);
}
.rec-card.primary::before {
  content: ''; position: absolute; top: -20px; right: -20px;
  width: 80px; height: 80px; border-radius: 50%;
  background: rgba(255,255,255,.12);
}
.rec-card.primary .rec-label, .rec-card.primary .rec-sub { color: rgba(255,255,255,.88); }
.rec-card.primary .rec-value { color: #fff; }
.rec-card.warn { background: var(--warn-soft); border-color: #f5c97a; }
.rec-card.danger { background: var(--neg-soft); border-color: #f5b0b0; }
.rec-label {
  font-size: 11px; color: var(--muted); margin-bottom: 5px;
  letter-spacing: .4px; text-transform: uppercase; font-weight: 600;
}
.rec-value { font-size: 22px; font-weight: 800; line-height: 1.2; letter-spacing: -.5px; }
.rec-value.small { font-size: 16px; }
.rec-sub { font-size: 11px; color: var(--muted-soft); margin-top: 4px; }

/* ===== table ===== */
.detail-table-wrap {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm);
}
.detail-table-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border-soft);
  background: linear-gradient(180deg, #fff, #fafbfd);
}
.detail-table-head h3 { margin: 0; font-size: 14px; font-weight: 700; }
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; user-select: none; }
.switch input { margin: 0; width: 16px; height: 16px; accent-color: var(--primary); }
.table-tip {
  font-size: 11px; color: var(--muted-soft); padding: 8px 16px 12px; margin: 0;
  background: var(--bg-soft); text-align: center;
}

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-height: 60vh; overflow-y: auto; }
.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid th, .grid td {
  padding: 10px; border-bottom: 1px solid var(--border-soft);
  border-right: 1px solid var(--border-soft);
  white-space: nowrap; text-align: right;
}
.grid th {
  background: #f7f8fa; color: var(--muted); font-weight: 600;
  text-align: center; position: sticky; top: 0; z-index: 1;
  font-size: 12px; letter-spacing: .2px;
}
.grid td:first-child, .grid th:first-child { text-align: center; }
.grid .qty { text-align: center; font-weight: 700; }
.grid .platform { text-align: right; }
.grid .min, .grid .max { font-weight: 700; }
.grid td .sub { font-size: 10px; color: var(--muted-soft); font-weight: 400; line-height: 1.3; }
.grid tbody tr:hover { background: var(--primary-softer); }
.grid tbody tr:active { background: var(--primary-soft); }
.grid tbody tr.best {
  background: linear-gradient(90deg, var(--primary-soft), #f3f7ff);
  box-shadow: inset 3px 0 0 var(--primary);
}
.grid .best-tag {
  display: inline-block; padding: 2px 6px; margin-left: 4px;
  background: linear-gradient(135deg, var(--primary), #5b8fff); color: #fff;
  border-radius: 4px; font-size: 9px; font-weight: 700; letter-spacing: .3px;
}
.grid th.sortable { cursor: pointer; user-select: none; transition: background .12s; }
.grid th.sortable:hover, .grid th.sortable:active { background: #eef1f6; color: var(--text); }
.grid th.sortable .sort-arrow { margin-left: 3px; color: var(--primary); font-size: 11px; font-weight: 700; }
.grid th.sorted-asc, .grid th.sorted-desc { background: var(--primary-soft); color: var(--primary-dark); }

.neg { color: var(--neg); font-weight: 600; }
.pos { color: var(--pos); font-weight: 600; }
.muted { color: var(--muted-soft); }

/* ===== modal ===== */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20,30,50,.5); backdrop-filter: blur(2px); animation: fadeIn2 .2s ease; }
@keyframes fadeIn2 { from { opacity: 0; } to { opacity: 1; } }
.modal-panel {
  position: relative; background: var(--panel); border-radius: 18px 18px 0 0;
  width: 100%; max-width: 640px; max-height: 88vh; overflow: hidden;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  animation: slideUp .28s cubic-bezier(.32,.72,0,1);
}
.modal-panel::before {
  content: ''; position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  width: 40px; height: 4px; background: var(--border); border-radius: 2px; z-index: 2;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 18px 14px; border-bottom: 1px solid var(--border);
  padding-top: 22px;
}
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 700; }
.modal-close {
  border: none; background: transparent; font-size: 26px;
  color: var(--muted); cursor: pointer; width: 36px; height: 36px;
  border-radius: 8px; line-height: 1; transition: all .15s;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--bg-soft); color: var(--text); }
.modal-body { padding: 18px; overflow-y: auto; flex: 1; }
.modal-body h3 { font-size: 14px; margin: 0 0 12px; color: var(--text); font-weight: 700; }
.modal-body h3:not(:first-child) { margin-top: 20px; }
.modal-body .grid th, .modal-body .grid td { font-size: 12px; padding: 9px 8px; }
.modal-body .grid input {
  width: 70px; padding: 7px 9px; border: 1.5px solid var(--border);
  border-radius: 6px; font-size: 13px; transition: border .15s;
}
.modal-body .grid input:focus { outline: none; border-color: var(--primary); }
#platform-table td:first-child { font-weight: 600; text-align: left; }
.modal-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 18px; border-top: 1px solid var(--border);
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  background: #fff;
}

/* ===== toast ===== */
.toast {
  position: fixed; bottom: 32px; left: 50%;
  transform: translateX(-50%) translateY(40px);
  background: rgba(26,34,51,.95); color: #fff; padding: 12px 22px;
  border-radius: 24px; font-size: 14px; opacity: 0;
  transition: all .3s cubic-bezier(.32,.72,0,1); z-index: 200; pointer-events: none;
  max-width: 90vw; text-align: center; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
  backdrop-filter: blur(8px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { background: linear-gradient(135deg, var(--good), #22c55e); }
.toast.err { background: linear-gradient(135deg, var(--neg), #ef4444); }

/* scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #cbd2d9; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #9aa5b1; }
::-webkit-scrollbar-track { background: transparent; }

/* ===== onboarding ===== */
.onboard { position: fixed; inset: 0; z-index: 300; }
.onboard[hidden] { display: none !important; }
.onboard-mask {
  position: absolute; inset: 0;
  background: rgba(20,30,50,.55);
  backdrop-filter: blur(2px);
  animation: onboardFade .25s ease;
}
@keyframes onboardFade { from { opacity: 0; } to { opacity: 1; } }

/* 高亮框：用 box-shadow 模拟挖空效果 */
.onboard-spot {
  position: absolute;
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(20,30,50,.55);
  border: 2px solid var(--primary);
  transition: all .3s cubic-bezier(.32,.72,0,1);
  pointer-events: none;
  z-index: 1;
}

.onboard-tip {
  position: absolute;
  background: #fff;
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: 0 12px 32px rgba(0,0,0,.25);
  width: 280px;
  max-width: calc(100vw - 32px);
  z-index: 2;
  animation: onboardTipIn .3s cubic-bezier(.32,.72,0,1);
}
@keyframes onboardTipIn {
  from { opacity: 0; transform: translateY(6px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.onboard-step {
  font-size: 11px; color: var(--primary); font-weight: 700;
  letter-spacing: .5px; margin-bottom: 6px;
}
.onboard-title { font-size: 16px; font-weight: 700; margin-bottom: 8px; color: var(--text); }
.onboard-desc { font-size: 13px; color: var(--muted); line-height: 1.6; margin-bottom: 14px; }
.onboard-desc b { color: var(--text); font-weight: 600; }
.onboard-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.onboard-skip {
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 13px; padding: 8px 12px; border-radius: 6px;
}
.onboard-skip:hover { background: var(--bg-soft); color: var(--text); }
.onboard-next { min-height: 36px; padding: 8px 18px; font-size: 14px; }
/* 小箭头 */
.onboard-tip::after {
  content: ''; position: absolute;
  width: 12px; height: 12px; background: #fff;
  border-radius: 2px; transform: rotate(45deg);
}
.onboard-tip.pos-below::after { top: -6px; left: 50%; margin-left: -6px; }
.onboard-tip.pos-above::after { bottom: -6px; left: 50%; margin-left: -6px; }
.onboard-tip.pos-left::after { right: -6px; top: 50%; margin-top: -6px; }
.onboard-tip.pos-right::after { left: -6px; top: 50%; margin-top: -6px; }
