:root {
  --navy: #1F3864;
  --navy-2: #2C4C82;
  --ink: #1C2430;
  --grey: #6B7684;
  --line: #E3E8F0;
  --bg: #F4F6FA;
  --card: #FFFFFF;
  --red: #B3261E;
  --amber: #B26A00;
  --green: #1E6B4F;
  --shadow: 0 2px 10px rgba(31, 56, 100, .07);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  padding-bottom: 74px;
  position: relative;
}

/* ---------- top bar ---------- */
#topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(135deg, #1F3864 0%, #2C4C82 100%);
  color: #fff;
  padding: 14px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 3px 12px rgba(31, 56, 100, .25);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 34px; height: 34px; flex: 0 0 34px;
  border-radius: 9px; background: rgba(255,255,255,.16);
  display: grid; place-items: center;
  font-weight: 700; font-size: 17px; letter-spacing: 0;
}
.titles { min-width: 0; }
.titles h1 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: .5px; }
.titles p { margin: 1px 0 0; font-size: 11px; opacity: .72; }
.top-actions { display: flex; align-items: center; gap: 8px; }

.ghost-select {
  appearance: none;
  background: rgba(255,255,255,.14);
  color: #fff;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
  font-family: inherit;
}
.ghost-select option { color: #222; }
.icon-btn {
  width: 28px; height: 28px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.3);
  background: rgba(255,255,255,.12);
  color: #fff; font-size: 14px; line-height: 1;
  cursor: pointer;
}

/* ---------- layout ---------- */
#view { padding: 12px 12px 8px; }
.section-title {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 16px 2px 8px;
}
.section-title h2 {
  margin: 0; font-size: 14px; font-weight: 600; color: var(--navy);
  letter-spacing: .3px;
}
.section-title span { font-size: 11px; color: var(--grey); }

.card {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 10px;
}

/* KPI grid */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 4px; }
.kpi {
  background: var(--card); border-radius: 12px; padding: 12px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi::after {
  content: ""; position: absolute; right: -18px; top: -18px;
  width: 56px; height: 56px; border-radius: 50%;
  background: rgba(31,56,100,.05);
}
.kpi .label { font-size: 11px; color: var(--grey); }
.kpi .value { font-size: 24px; font-weight: 700; color: var(--navy); line-height: 1.2; margin-top: 2px; }
.kpi .value small { font-size: 11px; font-weight: 500; color: var(--grey); margin-left: 2px; }
.kpi .foot { font-size: 10.5px; color: var(--grey); margin-top: 2px; }

/* tabs in card */
.seg {
  display: flex; background: #EDF1F8; border-radius: 9px; padding: 3px; margin-bottom: 10px;
}
.seg button {
  flex: 1; border: 0; background: transparent; padding: 7px 4px;
  font-size: 12.5px; color: var(--grey); border-radius: 7px; cursor: pointer;
  font-family: inherit;
}
.seg button.active { background: #fff; color: var(--navy); font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,.08); }

/* list rows */
.row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 2px; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row .rank {
  width: 20px; text-align: center; font-size: 11px; color: var(--grey); flex: 0 0 20px;
}
.row .main { flex: 1; min-width: 0; }
.row .name { font-size: 13.5px; font-weight: 600; }
.row .meta { font-size: 11px; color: var(--grey); }
.row .score { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.row .chev { color: #C2C9D6; font-size: 15px; }

.tag {
  display: inline-block; font-size: 10.5px; padding: 1px 6px; border-radius: 5px;
  margin-left: 4px; font-weight: 500; vertical-align: 1px;
}
.tag.green { background: #E7F3EC; color: var(--green); }
.tag.blue { background: #E8EEF9; color: var(--navy); }
.tag.amber { background: #FBF1E0; color: var(--amber); }
.tag.red { background: #FBEAE8; color: var(--red); }
.tag.grey { background: #EEF1F5; color: var(--grey); }

.score.hi { color: var(--green); }
.score.mid { color: var(--navy); }
.score.low { color: var(--amber); }
.score.bad { color: var(--red); }

/* forms */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 11.5px; color: var(--grey); margin-bottom: 4px; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
  width: 100%; padding: 9px 10px; font-size: 13px; font-family: inherit;
  border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--navy-2); box-shadow: 0 0 0 3px rgba(44,76,130,.08); }
textarea { resize: vertical; min-height: 60px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 14px; border-radius: 10px; border: 1px solid var(--navy);
  background: var(--navy); color: #fff; font-size: 13px; font-family: inherit;
  cursor: pointer; font-weight: 500;
}
.btn:active { transform: translateY(1px); }
.btn.block { width: 100%; }
.btn.ghost { background: #fff; color: var(--navy); }
.btn.danger { background: #fff; color: var(--red); border-color: #E6BDB8; }
.btn.small { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-row { display: flex; gap: 8px; margin-top: 12px; }
.btn-row .btn { flex: 1; }

/* check items */
.group-head {
  font-size: 11.5px; font-weight: 600; color: var(--navy);
  margin: 14px 0 4px; padding-bottom: 4px; border-bottom: 1px dashed var(--line);
  display: flex; justify-content: space-between;
}
.group-head em { font-style: normal; font-weight: 400; color: var(--grey); font-size: 10.5px; }
.item {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 8px 0; border-bottom: 1px solid #F1F4F9;
}
.item:last-child { border-bottom: 0; }
.item .cb {
  width: 19px; height: 19px; flex: 0 0 19px; margin-top: 1px;
  border: 1.5px solid #C7D0DE; border-radius: 5px; cursor: pointer;
  display: grid; place-items: center; font-size: 12px; color: #fff; background: #fff;
}
.item.on .cb { background: var(--navy); border-color: var(--navy); }
.item .txt { flex: 1; min-width: 0; }
.item .txt b { font-size: 12.5px; font-weight: 500; display: block; }
.item .txt i { font-style: normal; font-size: 10.5px; color: var(--grey); }
.item .pts { font-size: 12px; color: var(--grey); font-variant-numeric: tabular-nums; }
.item.on .pts { color: var(--red); font-weight: 600; }
.item .pts-input {
  width: 62px; flex: 0 0 62px; padding: 4px 6px; font-size: 12px;
  text-align: right; border-radius: 7px; border-color: #E0C6C2; color: var(--red);
  font-weight: 600;
}
.item { cursor: pointer; }
.row[data-action] { cursor: pointer; }

.totalbar {
  position: sticky; bottom: 74px; margin: 12px -12px 0; padding: 10px 16px;
  background: #fff; border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 -3px 10px rgba(31,56,100,.06);
}
.totalbar .t { font-size: 11.5px; color: var(--grey); }
.totalbar .v { font-size: 20px; font-weight: 700; color: var(--red); }

/* table */
.tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
.tbl th {
  text-align: left; font-weight: 500; color: var(--grey); font-size: 11px;
  padding: 6px 4px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.tbl td { padding: 7px 4px; border-bottom: 1px solid #F1F4F9; vertical-align: middle; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tr:last-child td { border-bottom: 0; }

/* misc */
.empty { text-align: center; color: var(--grey); font-size: 12px; padding: 26px 10px; }
.hint {
  font-size: 11px; color: var(--grey); line-height: 1.55;
  background: #F7F9FC; border-left: 2px solid #C9D3E4; padding: 8px 10px; border-radius: 0 8px 8px 0;
  margin: 8px 0;
}
.bar-line { height: 6px; border-radius: 3px; background: #EDF1F8; overflow: hidden; margin-top: 4px; }
.bar-line i { display: block; height: 100%; background: var(--navy-2); border-radius: 3px; }

.chip {
  display: inline-block; padding: 3px 8px; border-radius: 12px; font-size: 11px;
  background: #EDF1F8; color: var(--navy); margin: 0 4px 4px 0; cursor: pointer;
}
.rank-gap {
  text-align: center; font-size: 10.5px; color: #A8B2C2;
  margin: 2px 0 6px; letter-spacing: 1px;
}
.chip.on { background: var(--navy); color: #fff; }

/* settings rows */
.rule-row {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px;
  padding: 8px 0; border-bottom: 1px solid #F1F4F9; font-size: 12.5px;
}
.rule-row:last-child { border-bottom: 0; }
input.inline-num {
  width: 58px; flex: 0 0 58px; padding: 5px 6px; text-align: center; font-weight: 600;
  color: var(--navy); border-radius: 7px; font-size: 12.5px;
}

.footer-note { text-align: center; font-size: 10.5px; color: #A8B2C2; padding: 18px 0 6px; }

/* tabbar */
#tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 520px; background: #fff;
  display: flex; border-top: 1px solid var(--line);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  z-index: 30;
}
#tabbar button {
  flex: 1; border: 0; background: transparent; font-family: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10.5px; color: #8A94A6; padding: 4px 0; cursor: pointer;
}
#tabbar button svg { width: 19px; height: 19px; display: block; }
#tabbar button span { font-size: 16px; line-height: 1; }
#tabbar button.active { color: var(--navy); font-weight: 600; }

/* modal */
.modal {
  position: fixed; inset: 0; background: rgba(17,24,39,.45);
  display: grid; place-items: end center; z-index: 50;
}
.modal.hidden { display: none; }
.modal-card {
  width: 100%; max-width: 520px; max-height: 86vh; background: #fff;
  border-radius: 16px 16px 0 0; display: flex; flex-direction: column;
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(18px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 15px; color: var(--navy); }
.modal-head .icon-btn { border-color: var(--line); background: #F4F6FA; color: var(--grey); }
.modal-body { padding: 14px 16px; overflow: auto; font-size: 13px; }
.modal-foot { padding: 10px 16px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); display: flex; gap: 8px; }
.modal-foot .btn { flex: 1; }

/* svg charts */
.chart-wrap { margin: 6px 0 2px; }
svg text { font-family: inherit; }

@media (min-width: 720px) {
  #app { max-width: 760px; }
  #tabbar { max-width: 760px; }
  .modal-card { max-width: 760px; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
}

.del-btn {
  width: 26px; height: 26px; flex: 0 0 26px; border-radius: 50%;
  border: 1px solid var(--line); background: #fff; color: #8A94A6;
  font-size: 15px; line-height: 1; padding: 0; cursor: pointer; margin-left: 6px;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0 10px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; padding: 5px 11px; border-radius: 14px; font-size: 11.5px; background: #EDF1F8; color: #4A5567; }
.chip.on { background: var(--navy); color: #fff; }

.demo-bar {
  background: #FFF7E6; border: 1px solid #F3D9A4; color: #7A5B12;
  font-size: 11.5px; line-height: 1.55; padding: 9px 11px; border-radius: 10px;
  margin-bottom: 10px; cursor: pointer;
}
.demo-bar b { color: #8A5A00; }
.demo-bar span { display: block; margin-top: 3px; color: #A5791B; font-weight: 600; }

.part-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 8px; }
.part { display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: #F7F9FC; border: 1px solid var(--line); border-radius: 10px; padding: 8px 6px; }
.part span { font-size: 11.5px; color: var(--grey); }
.part input { width: 100%; text-align: center; font-size: 18px; font-weight: 700;
  color: var(--navy); padding: 4px 2px; border-radius: 8px; border-color: transparent; background: #fff; }
.part i { font-style: normal; font-size: 10.5px; color: #A8B2C2; }
.part-note { font-size: 11px; color: var(--grey); margin: 2px 0 8px; }
.part-note.on { color: var(--green); }

/* ---- login ---- */
.login-layer {
  position: fixed; inset: 0; z-index: 80; overflow: auto;
  background: linear-gradient(180deg, #1F3864 0%, #2C4C82 44%, #F4F6FA 44%, #F4F6FA 100%);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 30px 18px 40px;
}
.login-brand { text-align: center; color: #fff; margin-bottom: 18px; }
.login-brand .logo.lg {
  width: 52px; height: 52px; border-radius: 14px; margin: 0 auto 10px;
  background: rgba(255,255,255,.16); display: grid; place-items: center;
  font-size: 24px; font-weight: 700;
}
.login-brand h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: .5px; }
.login-brand p { margin: 4px 0 0; font-size: 11.5px; opacity: .72; }
.login-card {
  width: 100%; max-width: 380px; background: #fff; border-radius: 16px;
  padding: 16px; box-shadow: 0 10px 30px rgba(17,32,64,.18);
}
.login-err {
  background: #FBEAE8; color: var(--red); font-size: 12px;
  padding: 8px 10px; border-radius: 8px; margin-bottom: 10px;
}
.login-tip { font-size: 11px; color: var(--grey); line-height: 1.6; margin-top: 10px; }
.login-tip b { color: var(--navy); }

.user-btn {
  border: 1px solid rgba(255,255,255,.3); background: rgba(255,255,255,.12);
  color: #fff; font-size: 10.5px; padding: 5px 8px; border-radius: 8px;
  max-width: 112px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: inherit;
}

/* ---- 三段明细表 ---- */
.part-tbl td { padding: 8px 4px; }
.part-tbl .pname { font-size: 13px; font-weight: 600; }
.part-tbl .pmeta { font-size: 10.5px; color: var(--grey); margin-top: 1px; }
.part-grid.one { grid-template-columns: 1fr; }
.part-grid.one .part input { font-size: 26px; }

.acc-ops { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.mini-btn {
  border: 1px solid var(--line); background: #fff; color: var(--navy);
  font-size: 11.5px; padding: 5px 9px; border-radius: 7px; font-family: inherit;
  cursor: pointer; white-space: nowrap;
}
.mini-btn.danger { color: var(--red); border-color: #E6BDB8; }
.mini-btn:active { transform: translateY(1px); }
