/* 家庭财务投影器 — 财务投影 UI */
:root {
  --bg: #f0f2f5;
  --surface: #fff;
  --border: #e4e7ec;
  --border-focus: #2563eb;
  --text: #1a1d21;
  --text-muted: #5f6773;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --income: #059669;
  --expense: #dc2626;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --nav-height: 52px;
}

* { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 15px;
}

/* ——— 导航 ——— */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.25rem;
  min-height: var(--nav-height);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1.5rem;
  box-shadow: var(--shadow);
}
.nav-brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
  margin-right: 0.5rem;
}
.nav-brand:hover { color: var(--primary); }
.nav-links { display: flex; flex-wrap: wrap; gap: 0.15rem 0.5rem; align-items: center; }
.nav a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  transition: color .15s, background .15s;
}
.nav a:hover { color: var(--primary); background: rgba(37,99,235,.08); }
.nav .nav-sep { width: 1px; height: 1.2rem; background: var(--border); margin: 0 0.25rem; }
.nav .paid-lock { color: var(--text-muted); font-size: 0.85rem; padding: 0.4rem 0.5rem; }
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; }
.nav-user { color: var(--text-muted); font-size: 0.9rem; padding: 0.4rem 0.5rem; }

/* ——— 主内容 ——— */
.main { max-width: 1200px; margin: 0 auto; padding: 1.75rem 1.25rem; }
h1 { font-size: 1.5rem; font-weight: 700; margin: 0 0 1rem; color: var(--text); }
h2 { font-size: 1.15rem; font-weight: 600; margin: 1.5rem 0 0.75rem; color: var(--text); }

/* ——— 卡片（首页仪表盘） ——— */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin: 0 0 1.5rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  transition: box-shadow .2s, border-color .2s;
}
.card:hover { box-shadow: var(--shadow-md); border-color: #d0d5dd; }
.card h3 { margin: 0 0 0.35rem; font-size: 0.8rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .02em; }
.card .num { margin: 0; font-size: 1.35rem; font-weight: 700; color: var(--text); }
.card.card--income .num { color: var(--income); }
.card.card--expense .num { color: var(--expense); }

/* ——— 表格 ——— */
.table-wrap { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; box-shadow: var(--shadow); }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.table th, .table td { padding: 0.6rem 0.9rem; text-align: left; border-bottom: 1px solid var(--border); }
.table th {
  background: #f8fafc;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: none; }
.table .num, .table td.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.table .income { color: var(--income); font-weight: 500; }
.table .expense { color: var(--expense); font-weight: 500; }
.table .row-actions { white-space: nowrap; }
.table .row-actions a, .table .row-actions .btn { margin-right: 0.35rem; }

/* ——— 表单 ——— */
.form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: flex-end;
  box-shadow: var(--shadow);
}
.form label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.9rem;
  color: var(--text);
}
.form label span { min-width: 0; }
.form input[type=text], .form input[type=number], .form input[type=date], .form input[type=password], .form select {
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  min-width: 100px;
  transition: border-color .15s, box-shadow .15s;
}
.form input:focus, .form select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.form button, .btn {
  padding: 0.45rem 0.9rem;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: none;
  transition: background .15s, color .15s;
}
.form button, .btn-primary { background: var(--primary); color: #fff; }
.form button:hover, .btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text-muted); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f8fafc; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; padding: 0.35rem 0.6rem; font-size: 0.8rem; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-link { background: none; color: var(--primary); padding: 0.35rem 0.5rem; font-size: 0.85rem; text-decoration: none; }
.btn-link:hover { text-decoration: underline; }

/* ——— 视图切换、链接 ——— */
.view-toggle { margin: 0.5rem 0; color: var(--text-muted); font-size: 0.9rem; }
.view-toggle a { color: var(--primary); text-decoration: none; }
.view-toggle a:hover { text-decoration: underline; }
.view-toggle span { font-weight: 600; }
.error { color: var(--expense); margin: 0.5rem 0; font-size: 0.9rem; }
.main a:not(.nav a):not(.btn) { color: var(--primary); text-decoration: none; }
.main a:not(.nav a):not(.btn):hover { text-decoration: underline; }

/* ——— 计划提前还款区块 ——— */
.repayments-row td.repayments-cell { border-bottom: 1px solid var(--border); padding: 0.6rem 0.9rem; vertical-align: top; background: #fafbfc; }
.repayments { margin-left: 0.5rem; padding: 0.75rem 1rem; background: var(--surface); border-radius: var(--radius-sm); border: 1px solid var(--border); max-width: 440px; }
.repayments-title { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.5rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.repayments-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; background: transparent; }
.repayments-table th { text-align: left; padding: 0.3rem 0.4rem; color: var(--text-muted); font-weight: 600; border: none; background: transparent; font-size: 0.75rem; }
.repayments-table td { padding: 0.3rem 0.4rem; border: none; vertical-align: middle; }
.repayments-table .repay-date, .repayments-table .repay-amount { padding: 0.35rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.85rem; }
.repayments-table .repay-date { min-width: 9em; }
.repayments-table .repay-amount { min-width: 5.5em; }
.repayments-table .repay-actions { white-space: nowrap; }
.repayments-table .btn-save { padding: 0.3rem 0.55rem; font-size: 0.8rem; background: var(--primary); color: #fff; border: none; border-radius: var(--radius-sm); cursor: pointer; margin-right: 0.35rem; }
.repayments-table .btn-save:hover { background: var(--primary-hover); }
.repayments-table .btn-del { padding: 0.3rem 0.55rem; font-size: 0.8rem; background: var(--text-muted); color: #fff; border: none; border-radius: var(--radius-sm); cursor: pointer; }
.repayments-table .btn-del:hover { background: var(--text); }

/* ——— 内联表单（表格内） ——— */
.form-inline { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.form-inline input[type=number], .form-inline input[type=date] { padding: 0.35rem 0.5rem; font-size: 0.85rem; width: auto; }
.form-hint { font-size: 0.85rem; color: var(--text-muted); margin: -0.5rem 0 1rem; }

/* ——— 帮助页面 ——— */
.help-section { margin-bottom: 2rem; }
.help-section h2 { margin-top: 0; }
.help-section ul, .help-section ol { padding-left: 1.5rem; line-height: 1.8; }
.help-details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  box-shadow: var(--shadow);
  transition: box-shadow .2s;
}
.help-details:hover { box-shadow: var(--shadow-md); }
.help-details summary {
  padding: 0.75rem 1rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  font-size: 0.95rem;
  list-style: none;
}
.help-details summary::before { content: "▸ "; color: var(--primary); }
.help-details[open] summary::before { content: "▾ "; }
.help-details p { padding: 0 1rem 0.75rem; margin: 0; color: var(--text-muted); }
.help-example {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
}
.help-example p { margin: 0.4rem 0; }
.help-example ul { margin: 0.4rem 0; padding-left: 1.5rem; }
.help-steps li { margin-bottom: 0.5rem; }
.help-quote {
  margin: 1rem 0 0;
  padding: 0.85rem 1.15rem;
  background: rgba(37,99,235,.06);
  border-left: 4px solid var(--primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.6;
}

/* ——— 拖拽上传区域 ——— */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
  margin-top: 1rem;
  transition: border-color .2s, background .2s;
  cursor: pointer;
}
.drop-zone:hover, .drop-zone--active {
  border-color: var(--primary);
  background: rgba(37,99,235,.04);
}

/* ——— 投影页左右分栏 ——— */
.proj-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.25rem;
  align-items: start;
}
.proj-sidebar { display: flex; flex-direction: column; gap: 1.2rem; }
.proj-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
}
.proj-panel-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  margin: 0 0 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.proj-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
  letter-spacing: 0;
  text-transform: none;
}
/* 面板间连接线 */
.proj-sidebar .proj-panel + .proj-panel {
  position: relative;
}
.proj-sidebar .proj-panel + .proj-panel::before {
  content: '';
  position: absolute;
  top: -1.2rem;
  left: 1.5rem;
  width: 3px;
  height: 1.2rem;
  background: var(--primary);
  opacity: 0.6;
  border-radius: 2px;
}
.proj-label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--text);
}
.proj-input {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  width: 100%;
}
.proj-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.proj-result { min-width: 0; }

/* ——— 数据源面板 ——— */
.proj-datasource {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}
.proj-ds-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  font-size: 0.8rem;
  transition: border-color .15s, background .15s;
}
.proj-ds-item:hover {
  border-color: var(--primary);
  background: rgba(37,99,235,.04);
}
.proj-ds-item--active {
  border-color: var(--primary);
  background: rgba(37,99,235,.08);
  box-shadow: 0 0 0 2px rgba(37,99,235,.15);
}
.proj-ds-icon { font-size: 1rem; flex-shrink: 0; }
.proj-ds-label { flex: 1; font-weight: 500; }
.proj-ds-count { color: var(--text-muted); font-size: 0.75rem; font-variant-numeric: tabular-nums; }

/* ——— 自定义 Tooltip（卡片悬停说明） ——— */
.card-tip {
  position: relative;
  cursor: help;
}
.card-tip .tip-text {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 220px;
  max-width: 300px;
  background: var(--text);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.55;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
  white-space: pre-line;
  z-index: 50;
  pointer-events: none;
}
.card-tip .tip-text::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--text);
}
.card-tip:hover .tip-text {
  display: block;
}

@media (max-width: 768px) {
  .proj-layout { grid-template-columns: 1fr; }
  .card-tip .tip-text { min-width: 180px; max-width: 260px; font-size: 0.72rem; }
}
