:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --card2: #f1f5f9;
  --text: #17233b;
  --text2: #5b6b84;
  --text3: #94a3b8;
  --primary: #2563eb;
  --primary2: #0ea5e9;
  --on-primary: #ffffff;
  --border: #e6eaf2;
  --danger: #e11d48;
  --success: #059669;
  --warning: #d97706;
  --shadow: 0 2px 12px rgba(15, 23, 42, .08);
  --radius: 16px;
}
html[data-theme="dark"] {
  --bg: #0b1220;
  --card: #172032;
  --card2: #1e2a3e;
  --text: #e7edf7;
  --text2: #9fb0c8;
  --text3: #5f7189;
  --primary: #3b82f6;
  --primary2: #22b8e6;
  --border: #263349;
  --shadow: 0 2px 14px rgba(0,0,0,.35);
}
* { 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(--text); font-size: 15px; line-height: 1.5;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 15px; color: var(--text); }
h1,h2,h3,p { margin: 0; }

/* ---------- 顶部 ---------- */
.app-header {
  position: sticky; top: 0; z-index: 30;
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  color: var(--on-primary);
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; box-shadow: var(--shadow);
}
.app-header .logo {
  width: 34px; height: 34px; border-radius: 10px; background: rgba(255,255,255,.22);
  display: flex; align-items: center; justify-content: center; font-size: 17px; font-weight: 700;
}
.app-header .title { font-size: 17px; font-weight: 700; flex: 1; }
.app-header .hbtn {
  background: rgba(255,255,255,.18); border: none; color: #fff; border-radius: 9px;
  padding: 6px 10px; font-size: 13px;
}
.app-header .hbtn:active { background: rgba(255,255,255,.3); }

/* ---------- 底部导航 ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: var(--card); border-top: 1px solid var(--border);
  display: flex; padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 14px rgba(15,23,42,.06);
}
.bottom-nav .nav-item {
  flex: 1; background: none; border: none; color: var(--text3);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 4px 0; font-size: 11px;
}
.bottom-nav .nav-item svg { width: 22px; height: 22px; }
.bottom-nav .nav-item.active { color: var(--primary); }
.main { padding: 14px 14px 84px; max-width: 760px; margin: 0 auto; }
.page { display: none; }
.page.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 12px;
}
.card .c-title { font-size: 14px; color: var(--text2); font-weight: 600; margin-bottom: 10px; display: flex; align-items: center; gap: 6px; }
.card .c-title .more { margin-left: auto; font-size: 13px; color: var(--primary); cursor: pointer; }

/* 数字卡 */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.stat {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; position: relative; overflow: hidden;
}
.stat .s-label { font-size: 13px; color: var(--text2); }
.stat .s-value { font-size: 22px; font-weight: 800; margin-top: 4px; }
.stat .s-sub { font-size: 12px; color: var(--text3); margin-top: 2px; }
.stat.hero { background: linear-gradient(135deg, var(--primary), var(--primary2)); color: #fff; }
.stat.hero .s-label { color: rgba(255,255,255,.85); }
.stat.hero .s-sub { color: rgba(255,255,255,.7); }

/* chips */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  border: none; background: var(--card); color: var(--text2); border-radius: 999px;
  padding: 7px 14px; font-size: 13px; box-shadow: var(--shadow);
}
.chip.active { background: var(--primary); color: #fff; font-weight: 600; }

/* 搜索 */
.search { width: 100%; border: 1px solid var(--border); background: var(--card); border-radius: 12px; padding: 11px 14px; outline: none; margin-bottom: 12px; }
.search:focus { border-color: var(--primary); }

/* 列表行 */
.row {
  display: flex; align-items: center; gap: 10px; padding: 12px 0;
  border-bottom: 1px solid var(--border); cursor: pointer;
}
.row:last-child { border-bottom: none; }
.row .r-main { flex: 1; min-width: 0; }
.row .r-title { font-size: 15px; font-weight: 600; }
.row .r-sub { font-size: 13px; color: var(--text2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .r-right { text-align: right; flex-shrink: 0; }
.row .r-val { font-weight: 700; font-size: 15px; }
.row .r-tag { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; margin-left: 6px; vertical-align: 2px; }
.tag-blue { background: rgba(37,99,235,.12); color: var(--primary); }
.tag-green { background: rgba(5,150,105,.12); color: var(--success); }
.tag-red { background: rgba(225,29,72,.12); color: var(--danger); }
.tag-amber { background: rgba(217,119,6,.14); color: var(--warning); }
.tag-gray { background: var(--card2); color: var(--text2); }

/* 按钮 */
.btn {
  border: none; border-radius: 12px; padding: 12px 16px; font-size: 15px; font-weight: 600;
  background: var(--primary); color: #fff; width: 100%;
}
.btn:active { opacity: .85; }
.btn.ghost { background: var(--card2); color: var(--text); }
.btn.small { padding: 7px 12px; font-size: 13px; width: auto; border-radius: 9px; }
.btn.danger { background: var(--danger); }

/* 表单 */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 6px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--border); background: var(--card);
  border-radius: 12px; padding: 11px 12px; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.field .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field .row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.field .row4 { display: grid; grid-template-columns: 1.2fr 1fr 1fr 1fr; gap: 10px; }

/* 货品明细行 */
.item-row { display: grid; grid-template-columns: 1.1fr 1.3fr .8fr 1fr 1fr 30px; gap: 6px; margin-bottom: 8px; align-items: center; }
.item-row select, .item-row input {
  width: 100%; border: 1px solid var(--border); background: var(--card);
  border-radius: 10px; padding: 8px 6px; outline: none; font-size: 13px;
}
.item-row .del { border: none; background: none; color: var(--danger); font-size: 18px; padding: 0; }
.item-row input.bad { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); background: rgba(225,29,72,.06); }

/* 弹层 */
.mask {
  position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 50;
  display: none; align-items: flex-end; justify-content: center;
}
.mask.show { display: flex; }
.sheet {
  background: var(--bg); width: 100%; max-width: 760px; border-radius: 20px 20px 0 0;
  max-height: 92vh; overflow: auto; animation: up .25s ease;
}
@keyframes up { from { transform: translateY(40px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet .sh-head {
  position: sticky; top: 0; background: var(--card); padding: 14px 16px; z-index: 2;
  display: flex; align-items: center; border-bottom: 1px solid var(--border);
}
.sheet .sh-head .sh-title { flex: 1; font-size: 16px; font-weight: 700; }
.sheet .sh-head .close { background: var(--card2); border: none; border-radius: 50%; width: 30px; height: 30px; font-size: 16px; color: var(--text2); }
.sheet .sh-body { padding: 16px; }
.sheet .sh-foot { position: sticky; bottom: 0; background: var(--bg); padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); display: flex; gap: 10px; }

/* 登录页 */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: linear-gradient(150deg, #1d4ed8 0%, #0ea5e9 55%, #0f766e 100%);
}
.login-card {
  background: var(--card); border-radius: 22px; box-shadow: var(--shadow);
  width: 100%; max-width: 380px; padding: 30px 26px;
}
.login-card .lg-logo {
  width: 62px; height: 62px; border-radius: 16px; margin: 0 auto 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 30px; font-weight: 800;
}
.login-card h1 { text-align: center; font-size: 20px; margin-bottom: 4px; }
.login-card .lg-sub { text-align: center; color: var(--text3); font-size: 13px; margin-bottom: 22px; }
.login-card .field input { padding: 13px 14px; }
.login-card .btn { margin-top: 6px; padding: 13px; }

/* 空状态 */
.empty { text-align: center; color: var(--text3); padding: 40px 0; font-size: 14px; }
.empty .e-icon { font-size: 36px; margin-bottom: 8px; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: rgba(23,35,59,.92); color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 90; max-width: 86vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 曲线 */
.chart-box { width: 100%; }
.chart-box canvas { width: 100%; height: 130px; display: block; }

/* 表格（设置/详情） */
.kv { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--text2); }
.kv .v { font-weight: 600; text-align: right; }

/* 桌面优化 */
@media (min-width: 900px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .item-row { grid-template-columns: 1.3fr 1.6fr .8fr 1fr 1fr 30px; }
}
