* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #1a1a24;
  --bg-hover: #22222e;
  --border-color: #2a2a3a;
  --text-primary: #f0f0f5;
  --text-secondary: #8888a0;
  --text-muted: #5a5a70;
  --accent: #6366f1;
  --accent-dark: #4f46e5;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.3);
  --success: #22c55e;
  --success-dark: #16a34a;
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.1);
  --warning: #f59e0b;
  --shadow-dark: rgba(0, 0, 0, 0.5);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

.hidden {
  display: none !important;
}

/* 公共：渐变文字 */
.gradient-text-primary {
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.gradient-text-success {
  background: linear-gradient(135deg, var(--success) 0%, var(--success-dark) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ============ 登录页面 ============ */
#auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, var(--bg-primary) 0%, #0d0d18 100%);
}

.auth-container {
  width: 100%;
  max-width: 420px;
  padding: 40px;
  background: var(--bg-card);
  border-radius: 20px;
  border: 1px solid var(--border-color);
  box-shadow: 0 25px 50px -12px var(--shadow-dark);
}

.auth-container h1 {
  text-align: center;
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tabs {
  display: flex;
  margin: 30px 0 25px;
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 4px;
}

.tab {
  flex: 1;
  padding: 12px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: 10px;
  transition: all 0.3s ease;
}

.tab.active {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 15px var(--accent-glow);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-form input {
  padding: 14px 18px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  font-size: 15px;
  color: var(--text-primary);
  transition: all 0.3s ease;
}

.auth-form input::placeholder {
  color: var(--text-muted);
}

.auth-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.auth-form button {
  padding: 14px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-top: 8px;
}

.auth-form button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px var(--accent-glow);
}

.error {
  color: var(--danger);
  text-align: center;
  margin-top: 15px;
  font-size: 14px;
}

/* ============ 主页面 ============ */
header {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-card) 100%);
  border-bottom: 1px solid var(--border-color);
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
}

header h1 {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-info span {
  color: var(--text-secondary);
  font-size: 14px;
}

#logout-btn {
  padding: 8px 16px;
  background: var(--bg-hover);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.3s ease;
}

#logout-btn:hover {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

/* 导航 */
.main-nav {
  background: var(--bg-secondary);
  padding: 12px 24px;
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
}

.nav-btn {
  padding: 10px 20px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 10px;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.nav-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-btn.active {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 15px var(--accent-glow);
}

/* 内容区域 */
.view {
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
  animation: fadeIn 0.3s ease;
}

/* ============ 总览卡片 ============ */
.overview-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  background: var(--bg-card);
  border-radius: 16px;
  border: 1px solid var(--border-color);
  padding: 24px 6px;
  margin-bottom: 20px;
  gap: 24px;
  transition: all 0.3s ease;
}

.overview-card:hover {
  border-color: var(--accent);
}

.overview-left {
  flex: 0 0 auto;
  min-width: 130px;
}

/* 净资产标题与数值共用同一样式 */
.overview-title,
.overview-left p {
  font-size: 26px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--success) 0%, var(--success-dark) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

.overview-label-row {
  display: flex;
  align-items: baseline;
  flex-wrap: nowrap;
  gap: 6px;
  margin-bottom: 4px;
}

.header-return {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  white-space: nowrap;
  opacity: 0.85;
}

.overview-right {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0;
}

/* 目标达成进度区 */
.goal-progress-section {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-left: 1px solid var(--border-color);
  padding: 0 12px;
}

#goal-progress-list {
  width: 100%;
}

.goal-progress-item {
  margin-bottom: 10px;
}

.goal-progress-item:last-child {
  margin-bottom: 0;
}

.goal-progress-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.goal-progress-name {
  font-size: 12px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 80px;
}

.goal-progress-pct {
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  margin-left: 4px;
}

.goal-progress-bar-bg {
  height: 5px;
  background: var(--bg-secondary);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 2px;
}

.goal-progress-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

.goal-progress-amount {
  font-size: 10px;
  color: var(--text-muted);
}

/* ============ 页面区域标题 ============ */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.section-header h2,
.recent-assets h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

/* 兼容旧结构 */
.assets-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.assets-header h2 {
  font-size: 18px;
  font-weight: 600;
}

/* ============ 主按钮 ============ */
.btn-primary {
  padding: 12px 24px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px var(--accent-glow);
}

/* ============ 列表容器（三个tab共用） ============ */
#assets-list,
#recent-list,
#goals-list {
  background: var(--bg-card);
  border-radius: 16px;
  border: 1px solid var(--border-color);
  overflow: hidden;
}

/* ============ 列表项 ============ */
.asset-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-color);
  transition: all 0.2s ease;
}

.asset-item-sub {
  padding-left: 36px;
  background: rgba(255,255,255,0.01);
}

.asset-item-sub .asset-info h4 {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

.inline-rate {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 6px;
  opacity: 0.8;
}

.asset-item-sub .asset-amount {
  font-size: 15px;
  font-weight: 600;
}

.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px 8px;
  border-bottom: 1px solid var(--border-color);
}

.category-header-name {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

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

.asset-item:last-child {
  border-bottom: none;
}

.asset-item:hover {
  background: var(--bg-hover);
}

.asset-info {
  flex: 1;
  min-width: 0;
}

.asset-info h4 {
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.asset-info span {
  color: var(--text-muted);
  font-size: 13px;
}

.asset-amount {
  font-size: 18px;
  font-weight: 700;
  color: var(--success);
  margin: 0 20px;
  white-space: nowrap;
}

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

.asset-actions button {
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.edit-btn {
  background: var(--bg-hover);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.edit-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.delete-btn {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid transparent;
}

.delete-btn:hover {
  background: var(--danger);
  color: white;
}

.empty-message {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 15px;
}

/* ============ 分类资产区域 ============ */
.recent-assets h3 {
  margin-bottom: 16px;
}

/* ============ 饼图区域 ============ */
.pie-chart-container {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.pie-chart-container .chart-legend {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px 10px;
}

.pie-chart {
  width: 90px;
  height: 90px;
  transform: rotate(-90deg);
  flex-shrink: 0;
}

.pie-slice {
  transition: all 0.3s ease;
  transform-origin: 50px 50px;
}

.pie-slice:hover {
  transform: scale(1.05);
  filter: brightness(1.2);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 10px;
  width: 100%;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-secondary);
  padding: 2px 4px;
  border-radius: 4px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.legend-item:hover {
  background: var(--bg-hover);
}

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

.legend-text {
  white-space: nowrap;
}

.legend-value {
  color: var(--text-muted);
  font-size: 10px;
}

.pie-center-text {
  font-size: 8px;
  fill: var(--text-secondary);
  text-anchor: middle;
}

.pie-center-value {
  font-size: 10px;
  font-weight: 700;
  fill: var(--text-primary);
  text-anchor: middle;
}

/* ============ 弹窗 ============ */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 20px;
}

.modal-content {
  background: var(--bg-card);
  padding: 32px;
  border-radius: 20px;
  width: 100%;
  max-width: 450px;
  border: 1px solid var(--border-color);
  box-shadow: 0 25px 50px -12px var(--shadow-dark);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-content h3 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 24px;
  color: var(--text-primary);
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  font-size: 15px;
  color: var(--text-primary);
  transition: all 0.3s ease;
}

.form-group select {
  cursor: pointer;
}

.form-group select option {
  background: var(--bg-card);
  color: var(--text-primary);
}

.form-group textarea {
  height: 100px;
  resize: vertical;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 28px;
}

.form-actions button {
  padding: 12px 24px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.3s ease;
}

#cancel-btn,
#goal-cancel-btn {
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

#cancel-btn:hover,
#goal-cancel-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* ============ 目标拖拽 ============ */
.drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  min-width: 32px;
  align-self: stretch;
  margin-right: 4px;
  color: var(--text-muted);
  cursor: grab;
  opacity: 0.35;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  flex-shrink: 0;
  font-size: 18px;
  transition: opacity 0.2s;
}

.drag-handle:hover  { opacity: 0.7; }
.drag-handle:active { cursor: grabbing; opacity: 0.9; }

.goal-item {
  flex-wrap: nowrap !important;
}

.goal-item .asset-info {
  flex: 1 1 auto !important;
  min-width: 0;
}

.goal-item.dragging {
  opacity: 0.35;
  background: var(--bg-hover);
}

.goal-item.drag-over {
  border-top: 2px solid var(--accent);
}

/* ============ 响应式设计 ============ */
@media (max-width: 768px) {
  .auth-container {
    padding: 30px 24px;
  }

  .auth-container h1 {
    font-size: 24px;
  }

  header {
    padding: 14px 16px;
  }

  header h1 {
    font-size: 18px;
  }

  .user-info span {
    display: none;
  }

  .main-nav {
    padding: 10px 16px;
  }

  .nav-btn {
    padding: 8px 16px;
    font-size: 13px;
  }

  .view {
    padding: 16px;
  }

  .overview-card {
    flex-direction: column;
    align-items: flex-start;
    padding: 20px 10px;
  }

  .overview-left p {
    font-size: 22px;
  }

  .overview-right {
    width: 100%;
    flex-direction: row;
    align-items: center;
  }

  .goal-progress-section,
  .pie-chart-container {
    flex: 1;
    min-width: 0;
  }

  .goal-progress-name {
    max-width: 60px;
  }

  .pie-chart {
    width: 100px;
    height: 100px;
  }

  .assets-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .btn-primary {
    justify-content: center;
  }

  .asset-item {
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px;
  }

  .asset-info {
    flex: 1 1 100%;
  }

  .asset-amount {
    margin: 0;
    flex: 1;
  }

  .asset-actions {
    flex: 0 0 auto;
  }

  .modal-content {
    padding: 24px 20px;
    margin: 10px;
  }

  .form-actions {
    flex-direction: column;
  }

  .form-actions button {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .asset-actions button {
    padding: 8px 12px;
  }

  .tabs {
    margin: 24px 0 20px;
  }
}

/* 超窄屏（≤400px）：饼图与目标进度垂直排列，避免内容溢出或重叠 */
@media (max-width: 400px) {
  .overview-right {
    flex-direction: column;
    align-items: stretch;
  }

  .pie-chart-container {
    flex-direction: row;
    align-items: center;
    gap: 12px;
  }

  .pie-chart {
    width: 80px;
    height: 80px;
    flex-shrink: 0;
  }

  .chart-legend {
    flex: 1;
  }

  .goal-progress-section {
    width: 100%;
  }
}

/* ============ 滚动条 ============ */
::-webkit-scrollbar       { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============ 动画 ============ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
