/* ================= 基础 ================= */
:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --line: #e6e8ec;
  --line-2: #d9dce2;
  --ink: #14171c;
  --ink-2: #40465a;
  --muted: #8b919e;
  --pos: #d63a3a;
  --pos-bg: #fdf1f1;
  --pos-line: #f3cfcf;
  --neg: #0e9c66;
  --neg-bg: #ecf8f3;
  --neg-line: #c6e8d8;
  --brand: #16181d;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

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

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.pos { color: var(--pos); }
.neg { color: var(--neg); }
.flat { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; }
.hint.block { display: block; margin: 6px 0 0; }
.hint.center { text-align: center; padding: 28px 0; }
.spacer { flex: 1; }
.divider { height: 1px; background: var(--line); margin: 18px 0 14px; }
code {
  background: #f1f2f5; padding: 1px 5px; border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px;
}

/* ================= 按钮 ================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line-2); background: #fff; color: var(--ink);
  border-radius: 10px; padding: 9px 16px; font-size: 13.5px; font-weight: 550;
  transition: background .15s, border-color .15s, transform .1s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f7f8fa; }
.btn:active { transform: scale(.985); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #2a2e37; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: #f4f5f7; }
.btn.danger { color: #c22d2d; }
.btn.danger:hover { background: #fdf1f1; border-color: #f3cfcf; }
.btn.sm { padding: 7px 13px; font-size: 12.5px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px;
  border: 1px solid transparent; background: transparent; color: var(--ink-2);
  font-size: 15px; line-height: 1; transition: background .15s;
}
.icon-btn:hover { background: #edeff2; }
.icon-btn.sm { width: 28px; height: 28px; font-size: 17px; color: var(--muted); }
.icon-btn.sm:hover { color: var(--ink); }
.icon-btn:disabled { opacity: .3; cursor: not-allowed; }

/* ================= 登录 ================= */
.login-wrap {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--bg);
}
.login-card {
  width: 100%; max-width: 340px; background: var(--card);
  border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow); padding: 34px 28px 28px; text-align: center;
  animation: rise .3s ease;
}
.login-card h1 { font-size: 18px; margin: 14px 0 4px; letter-spacing: -.01em; }
.login-sub { color: var(--muted); font-size: 12.5px; margin: 0 0 22px; }
.login-card input {
  width: 100%; padding: 11px 14px; border: 1px solid var(--line-2);
  border-radius: 10px; background: #fafbfc; margin-bottom: 12px;
  font-size: 15px; transition: border-color .15s, background .15s;
}
.login-card input:focus { outline: none; border-color: #9aa2b1; background: #fff; }
.login-error { color: #c22d2d; font-size: 12.5px; min-height: 18px; margin: 12px 0 0; }

.logo-mark {
  width: 46px; height: 46px; margin: 0 auto; border-radius: 13px;
  background: var(--brand); color: #fff; display: flex;
  align-items: center; justify-content: center; font-size: 22px;
}
.logo-mark.sm { width: 26px; height: 26px; font-size: 13px; border-radius: 8px; margin: 0; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ================= 顶栏 ================= */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 20px;
  background: rgba(244, 245, 247, .86);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 650; font-size: 14.5px; letter-spacing: -.01em;
}

/* ================= 布局 ================= */
.container { max-width: 980px; margin: 0 auto; padding: 18px 16px 40px; }

.panel {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
  margin-bottom: 14px; box-shadow: var(--shadow);
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.panel-head h2 { font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 0; }
.panel-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line);
}

/* ================= 统计卡 ================= */
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px; margin-bottom: 14px;
}
.stat {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow);
}
.stat .k { font-size: 11.5px; color: var(--muted); letter-spacing: .01em; }
.stat .v {
  font-size: 20px; font-weight: 650; margin-top: 3px;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}

/* ================= 视图切换 ================= */
.tabs {
  display: inline-flex; gap: 2px; padding: 3px;
  background: #f1f2f5; border-radius: 10px;
}
.tab {
  border: none; background: transparent; color: var(--muted);
  padding: 6px 15px; border-radius: 8px; font-size: 13px; font-weight: 550;
  transition: background .15s, color .15s, box-shadow .15s;
}
.tab.active {
  background: #fff; color: var(--ink);
  box-shadow: 0 1px 3px rgba(16, 24, 40, .1);
}
.round-nav { display: flex; align-items: center; gap: 4px; }
.round-nav span {
  font-size: 12.5px; color: var(--ink-2); min-width: 78px; text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ================= 打卡网格 ================= */
.grid {
  display: grid; gap: 9px;
  grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
}
.cell {
  position: relative; aspect-ratio: 1 / 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; padding: 6px;
  border: 1px solid var(--line); border-radius: 11px; background: #fff;
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
  animation: pop .22s ease backwards;
}
@keyframes pop { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }

.cell:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(16, 24, 40, .1); }
.cell.empty { border-style: dashed; border-color: var(--line-2); background: #fafbfc; color: #c8ccd4; }
.cell.empty:hover { border-color: #b9bfc9; background: #f6f7f9; color: var(--muted); }
.cell-slot { font-size: 12px; font-variant-numeric: tabular-nums; }

.cell.filled.pos { background: var(--pos-bg); border-color: var(--pos-line); }
.cell.filled.neg { background: var(--neg-bg); border-color: var(--neg-line); }
.cell.filled.flat { background: #f7f8fa; border-color: var(--line-2); }

.cell-label { font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cell-value {
  font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums;
  letter-spacing: -.01em; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}
.cell.filled.pos .cell-value { color: var(--pos); }
.cell.filled.neg .cell-value { color: var(--neg); }
.cell.filled.flat .cell-value { color: var(--muted); }

.cell.today { box-shadow: inset 0 0 0 2px #16181d; }

.note-dot {
  position: absolute; top: 6px; right: 6px;
  width: 5px; height: 5px; border-radius: 50%; background: #b0b6c1;
}

/* ================= 曲线 ================= */
.curve { min-height: 60px; }
.curve-svg { width: 100%; height: auto; display: block; }

/* ================= 弹窗 ================= */
.overlay {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(20, 23, 28, .38);
  backdrop-filter: blur(3px);
  animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: 100%; max-width: 420px; background: #fff;
  border-radius: 18px; box-shadow: 0 24px 60px rgba(16, 24, 40, .22);
  max-height: calc(100dvh - 32px); overflow: auto;
  animation: rise .2s ease;
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 8px; position: sticky; top: 0; background: #fff; z-index: 2;
}
.sheet-head h3 { font-size: 15px; margin: 0; font-weight: 650; }
.sheet-body { padding: 6px 18px 18px; }

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: flex; align-items: baseline; gap: 6px;
  font-size: 12.5px; color: var(--ink-2); font-weight: 550; margin-bottom: 6px;
}
.field em { font-style: normal; font-weight: 400; color: var(--muted); font-size: 11.5px; }
.field input, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line-2);
  border-radius: 10px; background: #fafbfc; font-size: 15px;
  transition: border-color .15s, background .15s;
}
.field textarea { resize: vertical; min-height: 56px; font-size: 14px; }
.field input:focus, .field textarea:focus {
  outline: none; border-color: #9aa2b1; background: #fff;
}
.field input:disabled { color: var(--muted); background: #f4f5f7; }
#fPnl { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 17px; }

.quick { display: flex; flex-wrap: wrap; gap: 6px; margin: -6px 0 14px; }
.quick button {
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  padding: 5px 10px; font-size: 12px; color: var(--ink-2);
  font-variant-numeric: tabular-nums; transition: background .12s;
}
.quick button:hover { background: #f4f5f7; border-color: var(--line-2); }

.sheet-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.file-btn { cursor: pointer; }

/* 明细列表 */
.detail-sum {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 10px 12px; background: #f8f9fb; border-radius: 10px; margin-bottom: 10px;
  font-size: 12.5px; color: var(--muted);
}
.detail-sum b { font-size: 16px; font-variant-numeric: tabular-nums; }
.detail-list { display: flex; flex-direction: column; gap: 6px; }
.detail-row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; text-align: left; transition: background .12s;
}
.detail-row:hover { background: #fafbfc; }
.detail-row .d-date { font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.detail-row .d-val { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.detail-row .d-note {
  grid-column: 1 / -1; font-size: 11.5px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ================= 提示 ================= */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(0);
  background: rgba(20, 23, 28, .92); color: #fff; font-size: 13px;
  padding: 9px 18px; border-radius: 10px; z-index: 90;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .25);
  animation: rise .18s ease; pointer-events: none; max-width: 86vw; text-align: center;
}

.footer-note { text-align: center; color: var(--muted); font-size: 11.5px; margin: 22px 0 0; }

/* ================= 移动端 ================= */
@media (max-width: 640px) {
  .container { padding: 14px 12px 32px; }
  .topbar { padding: 10px 14px; }
  .panel { padding: 12px 12px; border-radius: 13px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(66px, 1fr)); gap: 7px; }
  .cell { border-radius: 10px; padding: 4px; }
  .cell-value { font-size: 12px; }
  .cell-label { font-size: 10px; }
  .stat { padding: 10px 12px; }
  .stat .v { font-size: 18px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .overlay { align-items: flex-end; padding: 0; }
  .sheet {
    max-width: 100%; border-radius: 20px 20px 0 0;
    max-height: 92dvh; padding-bottom: env(safe-area-inset-bottom);
    animation: slideUp .22s ease;
  }
  @keyframes slideUp { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
  .quick button { padding: 6px 12px; font-size: 12.5px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
