:root {
  --ink: #22302c;
  --ink-2: #5f6a65;
  --ink-3: #9aa5a0;
  --line: #e6ece9;
  --bg: #f4f6f5;
  --card: #ffffff;
  --green: #2f7567;
  --green-soft: #eaf3f0;
  --red: #c0392b;
  --red-soft: #fdeceb;
  --gold: #c9a84c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(34, 48, 44, 0.04), 0 8px 24px rgba(34, 48, 44, 0.05);
}

* { box-sizing: border-box; }

/* 组件自带 display 时，[hidden] 会被覆盖，统一提权 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

/* ---------------- 登录闸门 ---------------- */

.gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #e7f0ec 0%, var(--bg) 55%);
  z-index: 40;
}

.gate-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: 20px;
  padding: 28px 28px 24px;
  box-shadow: 0 20px 60px rgba(34, 48, 44, 0.12);
}

.gate-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-3);
  letter-spacing: 0.04em;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
}

.gate h1 {
  margin: 18px 0 6px;
  font-size: 22px;
  font-weight: 600;
}

.gate-sub {
  margin: 0 0 20px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-3);
}

.qr-wrap {
  position: relative;
  width: 240px;
  height: 240px;
  margin: 0 auto;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--line);
  padding: 10px;
}

.qr-box { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.qr-box svg { width: 100%; height: 100%; display: block; }

.qr-loading { font-size: 12px; color: var(--ink-3); }

.qr-expired {
  position: absolute;
  inset: 10px;
  background: rgba(255, 255, 255, 0.94);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 13px;
  color: var(--ink-2);
  border-radius: 10px;
}

.gate-steps {
  margin: 20px 0 0;
  padding-left: 18px;
  font-size: 12.5px;
  line-height: 2;
  color: var(--ink-2);
}
.gate-steps b { font-weight: 600; color: var(--ink); }

.gate-status {
  margin-top: 16px;
  text-align: center;
  font-size: 12.5px;
  color: var(--ink-3);
}

.gate-error {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 12.5px;
  line-height: 1.6;
}

/* ---------------- 布局 ---------------- */

.app {
  display: grid;
  grid-template-columns: 208px 1fr;
  min-height: 100vh;
}

.side {
  background: var(--card);
  border-right: 1px solid var(--line);
  padding: 22px 14px 18px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 22px;
}
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: 0.01em; }
.brand-sub { font-size: 11px; color: var(--ink-3); margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-2);
  font-size: 13.5px;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.nav-item .ico { font-size: 13px; width: 16px; text-align: center; color: var(--ink-3); }
.nav-item:hover { background: #f7f9f8; color: var(--ink); }
.nav-item.active { background: var(--green-soft); color: var(--green); font-weight: 600; }
.nav-item.active .ico { color: var(--green); }

.side-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--line); }
.sync-line { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: #ccd6d1; }
.sync-dot.on { background: var(--green); }
.sync-dot.busy { background: var(--gold); animation: pulse 1s infinite; }
.sync-dot.err { background: var(--red); }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: 0.35 } }

.sync-hint { margin-top: 6px; font-size: 11px; line-height: 1.5; color: var(--ink-3); }

.link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--ink-3);
  font-size: 12px;
  margin-top: 10px;
}
.link:hover { color: var(--green); }

.main { padding: 0 32px 40px; max-width: 1240px; width: 100%; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 22px;
  gap: 16px;
  position: sticky;
  top: 0;
  background: linear-gradient(var(--bg) 78%, rgba(244, 246, 245, 0));
  z-index: 5;
}

.month-nav { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink-2);
  font-size: 16px;
  line-height: 1;
}
.icon-btn:hover { border-color: #cfdad5; color: var(--ink); }

.month-label { font-size: 17px; font-weight: 600; min-width: 116px; text-align: center; letter-spacing: 0.01em; }

.top-actions { display: flex; gap: 8px; }

.btn {
  border-radius: 9px;
  border: 1px solid transparent;
  padding: 8px 14px;
  font-size: 13px;
  transition: 0.15s;
}
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:hover { background: #28685c; }
.btn.ghost { background: var(--card); border-color: var(--line); color: var(--ink-2); }
.btn.ghost:hover { border-color: #cfdad5; color: var(--ink); }
.btn.danger { color: var(--red); border-color: #f0d3cf; }
.btn.danger.ghost { background: #fff; }
.btn.wide { width: 100%; margin-top: 14px; }
.btn.small { padding: 5px 10px; font-size: 12px; }

/* ---------------- 卡片 ---------------- */

.view { animation: fade 0.18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(3px) } to { opacity: 1; transform: none } }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card.dark { background: #22302c; border-color: #22302c; color: #e8efec; display: flex; flex-direction: column; }

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.card-title { font-size: 13.5px; font-weight: 600; }
.card-title.light { color: #cfe0d9; font-weight: 500; }
.card-desc { font-size: 11.5px; color: var(--ink-3); margin-top: 3px; }

.grid-2 { display: grid; grid-template-columns: 1.45fr 1fr; gap: 16px; align-items: start; }

.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.kpi-k { font-size: 12px; color: var(--ink-3); }
.kpi-v {
  margin-top: 8px;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.kpi-s { margin-top: 6px; font-size: 11.5px; color: var(--ink-3); }

/* ---------------- 柱状图 ---------------- */

.bars > .empty { flex: 1; align-self: center; }
.bars {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 236px;
  padding-top: 18px;
}
.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 8px;
}
.bar-track {
  width: 100%;
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.bar {
  width: 68%;
  max-width: 46px;
  min-height: 2px;
  border-radius: 5px 5px 2px 2px;
  background: linear-gradient(180deg, #4f9a8b, #2f7567);
  transition: height 0.3s ease;
}
.bar.zero { background: #e6ece9; }
.bar-val { font-size: 10.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-label { font-size: 11px; color: var(--ink-3); }
.bar-col.current .bar { background: linear-gradient(180deg, #e0c876, #c9a84c); }
.bar-col.current .bar-label { color: var(--ink-2); font-weight: 600; }

/* ---------------- 本月构成 ---------------- */

.mix { display: flex; flex-direction: column; gap: 2px; }
.mix-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 13px;
}
.mix-row:last-child { border-bottom: 0; }
.mix-row.total { border-top: 1px solid var(--line); border-bottom: 0; margin-top: 4px; padding-top: 12px; font-weight: 600; }
.mix-k { color: var(--ink-2); }
.mix-row.total .mix-k { color: var(--ink); }
.mix-v { font-variant-numeric: tabular-nums; }
.mix-v.minus { color: var(--red); }
.mix-v.plus { color: var(--ink); }

/* ---------------- 表格 ---------------- */

.table-wrap { overflow: visible; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-3);
  padding: 8px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody td {
  padding: 11px 8px;
  font-size: 13px;
  border-bottom: 1px solid #f1f5f3;
  vertical-align: middle;
}
tbody tr:hover { background: #fafcfb; }
tbody tr:last-child td { border-bottom: 0; }
.t-right { text-align: right; font-variant-numeric: tabular-nums; }
.t-muted { color: var(--ink-3); font-size: 12px; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  background: var(--green-soft);
  color: var(--green);
}
.tag.upgrade { background: #eef2fb; color: #4a6ea8; }
.tag.refund { background: var(--red-soft); color: var(--red); }

.sum-row {
  display: flex;
  justify-content: flex-end;
  gap: 26px;
  padding-top: 14px;
  margin-top: 4px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--ink-3);
}
.sum-row b { color: var(--ink); font-size: 14px; font-variant-numeric: tabular-nums; }

.empty {
  padding: 44px 0;
  text-align: center;
  color: var(--ink-3);
  font-size: 13px;
}

.del-btn {
  border: 0;
  background: none;
  color: var(--ink-3);
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 6px;
}
.del-btn:hover { color: var(--red); background: var(--red-soft); }

/* ---------------- 明细工具条 ---------------- */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.seg {
  display: inline-flex;
  background: #eaeff0;
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.seg-item {
  border: 0;
  background: transparent;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 12.5px;
  color: var(--ink-2);
}
.seg-item.active { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(34,48,44,0.08); }

.search {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 13px;
  width: 220px;
  background: var(--card);
  color: var(--ink);
  outline: none;
}
.search:focus { border-color: #b9cfc8; }

/* ---------------- 核算 ---------------- */

.calc-list { display: flex; flex-direction: column; }
.calc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 13.5px;
}
.calc-row:last-child { border-bottom: 0; }
.calc-row .k { color: var(--ink-2); }
.calc-row .v { font-variant-numeric: tabular-nums; }
.calc-row .v.minus { color: var(--red); }
.calc-row.total {
  margin-top: 6px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  border-bottom: 0;
  font-size: 15px;
  font-weight: 600;
}
.calc-row.total .k { color: var(--ink); }

.balance {
  margin-top: 14px;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: #f3f7f5;
}
.balance-sub { margin-top: 6px; font-size: 11.5px; color: #8fa79f; }
.formula {
  margin-top: auto;
  padding-top: 18px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 11.5px;
  line-height: 1.9;
  color: #93a8a0;
}

/* ---------------- 表单 ---------------- */

.form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 32px; }
.field { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.field > span { color: var(--ink-2); white-space: nowrap; }
.field input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13.5px;
  color: var(--ink);
  background: #fbfcfc;
  outline: none;
  font-variant-numeric: tabular-nums;
}
.field input:focus { border-color: #b9cfc8; background: #fff; }
.field em { font-style: normal; color: var(--ink-3); font-size: 12px; width: 18px; flex: none; }
.field.block { margin-bottom: 12px; }
.field.block > span { width: 48px; }

.tips { margin-top: 12px; font-size: 11.5px; line-height: 1.75; color: var(--ink-3); }

.kv {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 13px;
}
.kv span { color: var(--ink-2); }
.kv b { font-weight: 500; }
.mono { font-family: Menlo, Consolas, monospace; font-size: 12px; }

/* ---------------- 弹窗 ---------------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(24, 34, 31, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 30;
}
.modal-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 16px;
  padding: 20px 22px 18px;
  box-shadow: 0 24px 60px rgba(24, 34, 31, 0.25);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  font-size: 15px;
  font-weight: 600;
}
.modal-card .seg { margin-bottom: 16px; }
.modal-foot { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.spacer { flex: 1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  background: rgba(34, 48, 44, 0.92);
  color: #fff;
  padding: 9px 16px;
  border-radius: 9px;
  font-size: 12.5px;
  z-index: 60;
  animation: fade 0.15s;
}

@media (max-width: 1080px) {
  .app { grid-template-columns: 1fr; }
  .side {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0; }
  .nav { flex-direction: row; }
  .side-foot { margin: 0 0 0 auto; border: 0; padding: 0; }
  .sync-hint, #btnLogout { display: none; }
  .main { padding: 0 16px 32px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .form { grid-template-columns: 1fr; }
  .bars { height: 180px; }
}

.notes {
  margin: 0;
  padding-left: 18px;
  font-size: 12.5px;
  line-height: 2;
  color: var(--ink-2);
}
.notes li::marker { color: #b9cfc8; }

.balance-split {
  display: flex;
  gap: 28px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.balance-split div { display: flex; flex-direction: column; gap: 4px; }
.balance-split span { font-size: 11px; color: #8fa79f; }
.balance-split b { font-size: 15px; font-weight: 500; color: #dbe8e3; font-variant-numeric: tabular-nums; }

.code-box {
  margin: 4px 0 20px;
  padding: 14px 0;
  text-align: center;
  font-size: 38px;
  font-weight: 600;
  letter-spacing: 6px;
  color: var(--ink);
  background: #f6f8f7;
  border-radius: 14px;
  font-variant-numeric: tabular-nums;
}
