/* ===== 基础重置 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --primary: #10b981;
  --primary-dark: #059669;
  --primary-light: #d1fae5;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --danger: #ef4444;
  --warn: #f59e0b;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
  --radius: 14px;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ===== 顶部应用栏 ===== */
.app-bar {
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  padding: 16px 20px 14px;
  padding-top: calc(env(safe-area-inset-top) + 16px);
}

.app-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.app-subtitle {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 2px;
}

/* ===== 视图容器 ===== */
.views {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px 90px;
  position: relative;
}

.view {
  display: none;
  animation: fadeIn 0.25s ease;
}

.view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== 卡片通用 ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.card-label {
  font-size: 13px;
  color: var(--text-light);
  margin-bottom: 10px;
  font-weight: 600;
}

/* ===== 总资产概览卡片 ===== */
.overview-card {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: #fff;
}

.overview-label {
  font-size: 13px;
  opacity: 0.85;
  margin-bottom: 6px;
  font-weight: 600;
}

.overview-total {
  font-size: 32px;
  font-weight: 800;
  margin-bottom: 14px;
  letter-spacing: 0.5px;
}

.overview-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.overview-item {
  flex: 1;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.overview-item-label {
  font-size: 11px;
  opacity: 0.85;
}

.overview-item-val {
  font-size: 14px;
  font-weight: 700;
}

.overview-monthly {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 12px;
}

.om-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.om-title {
  font-size: 13px;
  font-weight: 600;
  opacity: 0.95;
}

.btn-set {
  border: none;
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn-set:active {
  background: rgba(255, 255, 255, 0.4);
}

.overview-card .progress-track {
  background: rgba(255, 255, 255, 0.25);
}

.overview-card .progress-fill {
  background: #fff;
}

/* 副业进度条颜色(更高优先级覆盖默认渐变) */
.progress-fill.fill-side {
  background: linear-gradient(90deg, #fbbf24, #f59e0b);
}

.overview-card .progress-meta {
  color: rgba(255, 255, 255, 0.9);
}

/* ===== 设置弹窗快捷选择 ===== */
.quick-pick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.modal-tip {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.5;
}

/* ===== 当年目标卡片 ===== */
.year-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.year-tag {
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}

.year-amount {
  font-size: 16px;
  font-weight: 700;
}

.year-amount span {
  color: var(--primary-dark);
  font-size: 22px;
}

/* ===== 进度条 ===== */
.progress-wrap {
  width: 100%;
}

.progress-track {
  height: 8px;
  background: var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  border-radius: 8px;
  transition: width 0.5s ease;
}

.fill-emergency {
  background: linear-gradient(90deg, #fbbf24, #f59e0b);
}
.fill-safety {
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
}
.fill-freedom {
  background: linear-gradient(90deg, #818cf8, #6366f1);
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-light);
}

.progress-meta .hint {
  color: var(--text-muted);
}

/* ===== 累计本金卡片 ===== */
.stat-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 4px;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 14px;
  margin-bottom: 8px;
}

.alloc-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.alloc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.alloc-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-broad { background: var(--primary); }
.dot-sector { background: #6366f1; }
.dot-cash { background: #f59e0b; }

.alloc-name {
  flex: 1;
}

.alloc-pct {
  color: var(--text-light);
  font-weight: 600;
  min-width: 36px;
  text-align: right;
}

.alloc-val {
  font-weight: 700;
  min-width: 72px;
  text-align: right;
}

/* ===== 记录列表 ===== */
.record-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 340px;
  overflow-y: auto;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 24px 8px;
  font-size: 13px;
}

.record-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: 10px;
  border-left: 3px solid var(--primary);
}

.record-item .rec-date {
  font-size: 12px;
  color: var(--text-light);
  min-width: 64px;
}

.record-item .rec-note {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-item .rec-amount {
  font-weight: 700;
  color: var(--primary-dark);
}

.record-item .rec-del {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--danger);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
}

.record-item .rec-del:hover {
  opacity: 1;
}

/* ===== 浮动按钮 ===== */
.fab {
  position: fixed;
  right: 22px;
  bottom: 90px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
  cursor: pointer;
  z-index: 50;
  transition: transform 0.15s ease;
}

.fab:active {
  transform: scale(0.92);
}

.fab.hidden {
  display: none;
}

/* ===== 阶段卡片头部可点击 ===== */
.stage-header.clickable {
  cursor: pointer;
  user-select: none;
}

.stage-header.clickable .stage-num {
  transition: background 0.2s;
}

.stage-title-wrap {
  flex: 1;
  min-width: 0;
}

.stage-arrow {
  font-size: 22px;
  color: var(--text-muted);
  font-weight: 300;
  transition: transform 0.3s ease;
  flex-shrink: 0;
  margin-left: 8px;
}

.stage-card.expanded .stage-arrow {
  transform: rotate(90deg);
}

/* ===== 参数区域默认收起,展开动画 ===== */
.stage-detail {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease;
}

.stage-detail.expanded {
  max-height: 500px;
}

.stage-detail-inner {
  padding-top: 14px;
}

.detail-title {
  font-size: 12px;
  color: var(--text-light);
  font-weight: 600;
  margin-bottom: 10px;
}

/* 单列表格 */
.params-grid.single-col {
  grid-template-columns: 1fr;
}

/* ===== 参数设置卡片 ===== */
.params-card {
  background: #f8fafc;
  border: 1px solid var(--border);
}

.params-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 8px;
}

.param-field label {
  display: block;
  font-size: 12px;
  color: var(--text-light);
  margin-bottom: 6px;
}

.param-input-row {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
}

.param-input-row input {
  flex: 1;
  border: none;
  background: none;
  padding: 9px 0;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  width: 100%;
  min-width: 0;
}

.param-input-row input:focus {
  outline: none;
}

.param-unit {
  font-size: 13px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.params-tip {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ===== 计算公式区块 ===== */
.formula-box {
  margin-top: 14px;
  padding: 10px 12px;
  background: #f1f5f9;
  border-radius: 8px;
  border-left: 3px solid var(--primary);
}

.formula-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 600;
}

.formula {
  font-size: 13px;
  color: var(--text);
  font-family: "SF Mono", "Consolas", monospace;
  line-height: 1.6;
  word-break: break-all;
}

/* ===== 财务阶段卡片 ===== */
.stage-card {
  position: relative;
}

.stage-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.stage-num {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.stage-title {
  font-size: 16px;
  font-weight: 700;
}

.stage-desc {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 2px;
}

.goal-card .stage-num {
  background: #e0e7ff;
  color: #6366f1;
}

.stage-target-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-light);
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.stage-money {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.stage-target {
  font-weight: 600;
  color: var(--primary-dark);
}

.goal-card .stage-target {
  color: #6366f1;
}

.stage-action {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.btn-mini {
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn-mini:active {
  background: var(--bg);
}

/* ===== 纪律卡片 ===== */
.discipline-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.discipline-list li {
  padding-left: 22px;
  position: relative;
  font-size: 13px;
  color: var(--text);
}

.discipline-list li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--primary);
  font-weight: 700;
}

/* ===== 复利模拟器 ===== */
.sim-tip {
  font-size: 12px;
  color: var(--text-light);
  margin-bottom: 16px;
}

.sim-field {
  margin-bottom: 18px;
}

.sim-field label {
  display: block;
  font-size: 13px;
  color: var(--text-light);
  margin-bottom: 8px;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(16, 185, 129, 0.4);
}

input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
}

.sim-output {
  min-width: 56px;
  text-align: right;
  font-weight: 700;
  color: var(--primary-dark);
  font-size: 14px;
}

/* ===== 模拟结果 ===== */
.sim-result {
  background: #f8fafc;
  border-radius: 10px;
  padding: 14px;
  margin-top: 8px;
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
}

.result-label {
  font-size: 13px;
  color: var(--text-light);
}

.result-val {
  font-weight: 700;
  color: var(--text);
}

.result-val.profit {
  color: var(--primary-dark);
}

.result-row.highlight {
  border-top: 1px dashed var(--border);
  margin-top: 6px;
  padding-top: 10px;
}

.result-val.big {
  font-size: 20px;
  color: var(--primary-dark);
}

/* ===== 达标判断 ===== */
.sim-verdict {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 13px;
  text-align: center;
  font-weight: 600;
}

.sim-verdict.achieved {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.sim-verdict.short {
  background: #fef3c7;
  color: #92400e;
}

/* ===== 实际已投资数据 ===== */
.sim-actual {
  margin-top: 14px;
  padding: 12px 14px;
  background: #f1f5f9;
  border-radius: 10px;
  border-left: 3px solid var(--text-muted);
}

.actual-title {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 8px;
}

.actual-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-light);
  padding: 3px 0;
}

.actual-val {
  font-weight: 700;
  color: var(--text);
}

/* ===== 应用按钮 ===== */
.btn-apply {
  width: 100%;
  margin-top: 16px;
  padding: 13px;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.btn-apply:active {
  background: var(--primary-dark);
  transform: scale(0.98);
}

/* ===== 目标对比 ===== */
.compare-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--text-light);
}

.compare-item > span:first-child {
  min-width: 96px;
}

.compare-bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.compare-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  border-radius: 8px;
  transition: width 0.4s ease;
}

.compare-pct {
  min-width: 48px;
  text-align: right;
  font-weight: 600;
  color: var(--text);
}

/* ===== 底部导航 ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 40;
}

.nav-item {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  transition: color 0.15s ease;
}

.nav-icon {
  font-size: 20px;
  font-weight: 700;
}

.nav-item.active {
  color: var(--primary-dark);
}

/* ===== 弹窗 ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  animation: fadeOverlay 0.2s ease;
}

.modal-overlay.active {
  display: flex;
}

@keyframes fadeOverlay {
  from { background: rgba(0, 0, 0, 0); }
  to { background: rgba(0, 0, 0, 0.5); }
}

.modal {
  background: var(--card);
  width: 100%;
  max-width: 480px;
  border-radius: 18px 18px 0 0;
  padding: 20px;
  animation: slideUp 0.25s ease;
  padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.modal-header h2 {
  font-size: 17px;
}

.modal-close {
  border: none;
  background: none;
  font-size: 18px;
  color: var(--text-light);
  cursor: pointer;
  width: 32px;
  height: 32px;
}

.form-field {
  margin-bottom: 16px;
}

.form-field label {
  display: block;
  font-size: 13px;
  color: var(--text-light);
  margin-bottom: 6px;
}

.form-field input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  background: #f8fafc;
  color: var(--text);
}

.form-field input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--card);
}

.modal-footer {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.btn-cancel, .btn-save {
  flex: 1;
  padding: 13px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-family: inherit;
}

.btn-cancel {
  background: var(--bg);
  color: var(--text-light);
}

.btn-save {
  background: var(--primary);
  color: #fff;
}

.btn-save:active {
  background: var(--primary-dark);
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-80px);
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 200;
  transition: transform 0.3s ease;
  white-space: nowrap;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* ===== 大屏适配 ===== */
@media (min-width: 600px) {
  .views {
    max-width: 560px;
    margin: 0 auto;
    width: 100%;
  }
  .bottom-nav {
    max-width: 560px;
    margin: 0 auto;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 18px 18px 0 0;
  }
  .fab {
    right: calc(50% - 280px + 22px);
  }
}
