/* 个人工作台 · 样式 */
:root {
  --bg: #f4f5f9;
  --panel: #ffffff;
  --border: #e6e8ef;
  --border-strong: #d5d9e4;
  --text: #1f2430;
  --muted: #7b8496;
  --accent: #4f5bd5;
  --accent-dark: #3f49b5;
  --accent-soft: #eceefb;
  --income: #14a06a;
  --expense: #e04a63;
  --danger: #d6455d;
  --sidebar-bg: #20242f;
  --sidebar-text: #b9bfcd;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 24, 40, .05), 0 8px 24px rgba(20, 24, 40, .05);
  --sidebar-w: 200px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.muted { color: var(--muted); font-weight: 400; }
.link { color: var(--accent); text-decoration: underline; }

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

.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 20px; }

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  flex: none;
}

.brand-mark--lg { width: 44px; height: 44px; border-radius: 13px; font-size: 21px; }
.brand-text { color: #fff; font-weight: 600; font-size: 15px; }

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

.nav-item {
  display: block;
  padding: 9px 12px;
  border-radius: 9px;
  color: var(--sidebar-text);
  font-size: 14px;
  text-align: center;
  transition: background .15s, color .15s;
}

.nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav-item.is-active { background: var(--accent); color: #fff; font-weight: 600; }

.sidebar-foot { padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .08); }

.shell {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 24px;
  background: rgba(244, 245, 249, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-brand { font-weight: 600; font-size: 15px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.user-chip {
  padding: 3px 11px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 500;
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.view { padding: 22px 24px 48px; max-width: 1180px; width: 100%; }
.loading { padding: 40px 0; text-align: center; color: var(--muted); }

.app--auth .sidebar { display: none; }
.app--auth .shell { margin-left: 0; }
.app--auth .topbar { display: none; }

/* ------------------------- 通用块 ------------------------- */

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.page-title { margin: 0; font-size: 20px; font-weight: 600; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-title { margin: 0 0 14px; font-size: 15px; font-weight: 600; }
.card-head .card-title { margin: 0; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.grid-2 .card { margin-bottom: 0; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 22px; font-weight: 600; margin: 4px 0 2px; word-break: break-all; }
.stat-hint { color: var(--muted); font-size: 12px; }

.kv-list { list-style: none; margin: 0; padding: 0; }
.kv-list li { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border); }
.kv-list li:last-child { border-bottom: none; }
.kv-list--total { font-weight: 600; }

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

.form { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .field { margin: 0; }
.form-inline { flex-direction: row; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.form-inline .field { flex: 1 1 220px; }
.form-actions { display: flex; gap: 10px; }
.field--full { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 13px; color: var(--muted); }

.input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 91, 213, .13); }
.textarea { resize: vertical; min-height: 60px; }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #9aa2b4 50%), linear-gradient(135deg, #9aa2b4 50%, transparent 50%); background-position: calc(100% - 17px) 18px, calc(100% - 12px) 18px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 32px; }

.checklist { display: flex; flex-wrap: wrap; gap: 8px; }

.checkitem {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: #fbfcfe;
  font-size: 13px;
  cursor: pointer;
}

.checkitem:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }
.checkitem input { margin: 0; accent-color: var(--accent); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.toolbar .input { width: auto; flex: 1 1 180px; min-width: 130px; }

/* ------------------------- 按钮 ------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 15px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}

.btn:hover { background: #f7f8fb; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-sm { padding: 5px 11px; font-size: 13px; }
.btn-block { width: 100%; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-danger { background: #fff; border-color: #f0c3cb; color: var(--danger); }
.btn-danger:hover { background: #fdf1f3; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.sidebar-foot .btn-ghost { color: var(--sidebar-text); }
.sidebar-foot .btn-ghost:hover { background: rgba(255, 255, 255, .08); color: #fff; }

.btn.is-loading { position: relative; color: transparent !important; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  color: #fff;
  animation: ph-spin .7s linear infinite;
}

.btn:not(.is-loading).btn-danger.is-loading::after { color: var(--danger); }

@keyframes ph-spin { to { transform: rotate(360deg); } }

/* ------------------------- 列表与行 ------------------------- */

.list { display: flex; flex-direction: column; }

.row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}

.row:first-child { padding-top: 2px; }
.row:last-child { border-bottom: none; padding-bottom: 0; }
.row-main { flex: 1; min-width: 0; }
.row-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; }
.row-sub { color: var(--muted); font-size: 13px; word-break: break-word; }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px; }

.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: #eef0f6;
  color: #5b6478;
  font-size: 12px;
}

.secret { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 1px; color: var(--muted); }
.secret--revealed { color: var(--text); letter-spacing: 0; background: var(--accent-soft); padding: 1px 6px; border-radius: 5px; }

.amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount--income { color: var(--income); }
.amount--expense { color: var(--expense); }

.badge {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 500;
}

.badge--muted { background: #eef0f6; color: #5b6478; }
.badge--ok { background: #e7f6ef; color: #0f7d52; }
.badge--danger { background: #fdedf0; color: #c0394f; }

.empty { padding: 34px 12px; text-align: center; }
.empty-title { font-weight: 600; color: var(--muted); }
.empty-text { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ------------------------- 简易条形图 ------------------------- */

.bars { display: flex; flex-direction: column; gap: 11px; }
.bar-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 13px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-amount { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-track { height: 8px; margin-top: 5px; border-radius: 999px; background: #eef0f6; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), #7b84e8); }

/* ------------------------- 登录页 ------------------------- */

.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 30px 26px;
}

.auth-head { text-align: center; margin-bottom: 22px; }
.auth-title { margin: 12px 0 4px; font-size: 19px; }
.auth-sub { margin: 0; color: var(--muted); font-size: 13px; }
.auth-card .form { margin-bottom: 14px; }

.notice {
  padding: 9px 12px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 13px;
  margin-bottom: 14px;
}

.notice--warn { background: #fff6e6; color: #a2681a; }

/* ------------------------- 上传区 ------------------------- */

.dropzone {
  padding: 26px 16px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: #fbfcfe;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.dropzone:hover, .dropzone--active { border-color: var(--accent); background: var(--accent-soft); }
.dropzone-title { margin: 0 0 4px; }
.dropzone p { margin: 0 0 4px; }

/* ------------------------- 提示条与弹窗 ------------------------- */

.toast-host {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(460px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  padding: 10px 15px;
  border-radius: 10px;
  background: #2b3040;
  color: #fff;
  font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(20, 24, 40, .18);
  opacity: 1;
  transition: opacity .3s, transform .3s;
}

.toast--error { background: var(--danger); }
.toast--success { background: var(--income); }
.toast--hide { opacity: 0; transform: translateY(-8px); }

.modal-host { position: fixed; inset: 0; z-index: 100; pointer-events: none; }
.modal-host:empty { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  background: rgba(20, 24, 40, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 20px 50px rgba(20, 24, 40, .25);
}

.modal-title { margin: 0 0 8px; font-size: 16px; }
.modal-text { margin: 0 0 18px; color: var(--muted); font-size: 13.5px; word-break: break-word; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ------------------------- 移动端 ------------------------- */

@media (max-width: 768px) {
  .app { flex-direction: column; }

  .sidebar {
    top: auto;
    right: 0;
    bottom: 0;
    width: 100%;
    flex-direction: row;
    align-items: center;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(255, 255, 255, .1);
  }

  .sidebar .brand, .sidebar-foot { display: none; }

  .nav { flex-direction: row; justify-content: space-between; gap: 2px; }

  .nav-item {
    flex: 1;
    padding: 8px 2px;
    font-size: 12px;
    text-align: center;
    white-space: nowrap;
  }

  .shell { margin-left: 0; padding-bottom: 62px; }

  .topbar { padding: 12px 14px; }
  .view { padding: 16px 14px 30px; }

  .grid-2 { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-value { font-size: 19px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }

  .card { padding: 15px; border-radius: 10px; }

  .row { flex-direction: column; gap: 8px; }
  .row-actions { justify-content: flex-start; width: 100%; }
  .row-actions .amount { margin-right: auto; }

  .toolbar .input, .toolbar .btn { flex: 1 1 100%; width: 100%; }

  .user-chip { max-width: 34vw; }
}
