/* ============================================
   资产理财管理工具 - 样式表
   设计理念：premium、clean、glass morphism
   ============================================ */

/* ===== CSS 变量 / 主题 ===== */
:root {
  --bg: #f0f4f8;
  --bg-gradient: linear-gradient(135deg, #f0f4f8 0%, #e8eef5 100%);
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-hover: #f1f5f9;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --primary: #059669;
  --primary-light: #d1fae5;
  --primary-dark: #047857;
  --accent: #d97706;
  --accent-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --info: #0284c7;
  --info-light: #e0f2fe;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 25px -3px rgba(0,0,0,0.08), 0 4px 10px -4px rgba(0,0,0,0.04);
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.8);
  --glass-blur: blur(20px) saturate(180%);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  --mono: "SF Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1a2332 100%);
  --surface: #1e293b;
  --surface-2: #334155;
  --surface-hover: #334155;
  --border: #334155;
  --border-light: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-light: #64748b;
  --primary: #10b981;
  --primary-light: rgba(16, 185, 129, 0.15);
  --primary-dark: #059669;
  --accent: #f59e0b;
  --accent-light: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --danger-light: rgba(239, 68, 68, 0.15);
  --success: #22c55e;
  --success-light: rgba(34, 197, 94, 0.15);
  --warning: #f59e0b;
  --warning-light: rgba(245, 158, 11, 0.15);
  --info: #38bdf8;
  --info-light: rgba(56, 189, 248, 0.15);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.3), 0 2px 4px -2px rgba(0,0,0,0.2);
  --shadow-lg: 0 10px 25px -3px rgba(0,0,0,0.4), 0 4px 10px -4px rgba(0,0,0,0.2);
  --glass-bg: rgba(30, 41, 59, 0.7);
  --glass-border: rgba(51, 65, 85, 0.5);
  --glass-blur: blur(20px) saturate(180%);
}

/* ===== 全局重置 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--transition), color var(--transition);
}

/* ===== 工具类 ===== */
.hidden { display: none !important; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.muted-text { color: var(--text-muted); }
.muted-text.small { font-size: 0.8rem; }

/* ===== Glass 效果 ===== */
.glass {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.card-header-row .card-title { margin-bottom: 0; }

/* 可折叠卡片 */
.collapsible-header {
  cursor: pointer;
  user-select: none;
  transition: opacity 0.2s ease;
}
.collapsible-header:hover { opacity: 0.78; }
.collapsible-header .chevron {
  color: var(--text-muted);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  flex-shrink: 0;
}
.collapsible.collapsed .collapsible-body { display: none; }
.collapsible.collapsed .chevron { transform: rotate(-90deg); }

/* ===== 顶栏 ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--primary);
}

.logo-text {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

.net-worth-display {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 0.25rem 0.75rem;
  border-left: 1px solid var(--border);
  margin-right: 0.25rem;
}

.net-worth-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.net-worth-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.icon-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-light);
  transform: translateY(-1px);
}

/* ===== 标签导航 ===== */
.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.75rem 1.5rem 0;
  max-width: 1200px;
  margin: 0 auto;
  overflow-x: auto;
}

.tab {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.1rem;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  border-radius: var(--radius-xs) var(--radius-xs) 0 0;
}

.tab:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* ===== 主内容区 ===== */
.tab-content {
  display: none;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
  animation: fadeIn 0.3s ease;
}

.tab-content.active { display: block; }

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

/* ===== 页面头 ===== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ===== 按钮 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
  white-space: nowrap;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(5, 150, 105, 0.3);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-danger:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== 表格 ===== */
.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th {
  text-align: left;
  padding: 0.65rem 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tr:hover td { background: var(--surface-hover); }

.data-table .amount { font-variant-numeric: tabular-nums; font-weight: 600; }

.profit-pos { color: var(--success); }
.profit-neg { color: var(--danger); }

/* ===== 表单元素 ===== */
.form-group { margin-bottom: 1rem; }

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  transition: all var(--transition);
}

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

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

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* ===== 锁屏 ===== */
.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  background-image: var(--bg-gradient);
}

.lock-card {
  padding: 2.5rem;
  width: 360px;
  max-width: 90vw;
  text-align: center;
}

.lock-icon {
  display: flex;
  justify-content: center;
  margin-bottom: 1.25rem;
  color: var(--primary);
}

.lock-card h2 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

.pin-input {
  width: 100%;
  padding: 0.7rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  text-align: center;
  letter-spacing: 0.3em;
  background: var(--surface);
  color: var(--text);
  margin: 1rem 0 0.5rem;
}

.pin-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.lock-error {
  color: var(--danger);
  font-size: 0.8rem;
  margin-bottom: 0.5rem;
}

/* ===== 看板 ===== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem;
}

.stat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  flex-shrink: 0;
}

.stat-icon-primary { background: var(--primary-light); color: var(--primary); }
.stat-icon-accent { background: var(--accent-light); color: var(--accent); }
.stat-icon-success { background: var(--success-light); color: var(--success); }
.stat-icon-warning { background: var(--warning-light); color: var(--warning); }

.stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 0.15rem;
}

.dashboard-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.chart-card { min-height: 320px; }

.pie-chart-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 260px;
}

.pie-chart-container svg { max-width: 100%; }

.pie-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  justify-content: center;
  margin-top: 1rem;
  font-size: 0.8rem;
}

.pie-legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

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

.month-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-xs);
  background: var(--primary-light);
  color: var(--primary);
}

/* ===== 预算进度 ===== */
.budget-progress-list { display: flex; flex-direction: column; gap: 0.85rem; }

.budget-progress-item {
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.budget-progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.budget-progress-type {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.budget-progress-amounts {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.budget-progress-amounts .remaining { font-weight: 600; }
.budget-progress-amounts .remaining.over { color: var(--danger); }
.budget-progress-amounts .remaining.under { color: var(--success); }

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

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

.progress-bar-fill.normal { background: linear-gradient(90deg, var(--primary), var(--success)); }
.progress-bar-fill.warning { background: linear-gradient(90deg, var(--accent), var(--warning)); }
.progress-bar-fill.danger { background: linear-gradient(90deg, var(--danger), #f87171); }

.type-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-xs);
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* 资产子类型标记（基金品类/股票市场/主动被动） */
.sub-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-xs);
  font-size: 0.68rem;
  font-weight: 500;
  background: var(--info-light);
  color: var(--info);
  margin-left: 0.3rem;
  vertical-align: middle;
}

.sub-tag.sub-tag-active {
  background: var(--accent-light);
  color: var(--accent);
}

.sub-tag.sub-tag-passive {
  background: var(--primary-light);
  color: var(--primary);
}

.flexible-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-xs);
  font-size: 0.7rem;
  background: var(--accent-light);
  color: var(--accent);
  margin-left: 0.35rem;
}

/* ===== 空状态 ===== */
.empty-state {
  text-align: center;
  padding: 2rem 1rem;
}

/* ===== 月份选择器 ===== */
.month-selector {
  font-size: 1.1rem;
  font-weight: 700;
  padding: 0.3rem 0.8rem;
  font-variant-numeric: tabular-nums;
}

/* ===== 设置页 ===== */
.settings-section { margin-bottom: 1rem; }

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0;
  gap: 1rem;
}

.settings-label { display: flex; flex-direction: column; gap: 0.15rem; }
.settings-label > span:first-child { font-weight: 500; }

.settings-divider {
  height: 1px;
  background: var(--border);
  margin: 0.25rem 0;
}

.theme-options { display: flex; gap: 0.4rem; }

.theme-option {
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
}

.theme-option:hover { border-color: var(--primary); }

.theme-option.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.about-info { line-height: 1.8; font-size: 0.875rem; }
.about-info strong { color: var(--primary); }

/* ===== 模态框 ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
}

.modal-dialog {
  position: relative;
  width: 480px;
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.25s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 1.1rem; font-weight: 600; }

.modal-close {
  border: none;
  background: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  transition: color var(--transition);
}

.modal-close:hover { color: var(--danger); }

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease;
  max-width: 340px;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}

.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }
.toast.info { background: var(--info); color: #fff; }

/* ===== 类型管理列表 ===== */
.type-manager-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  margin-bottom: 0.5rem;
}

.type-manager-item .drag-handle {
  color: var(--text-light);
  cursor: grab;
  margin-right: 0.5rem;
}

.type-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ===== 投资记录行 ===== */
.investment-row-date { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ===== 操作按钮组 ===== */
.action-btns { display: flex; gap: 0.3rem; justify-content: center; }

.action-btn {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all var(--transition);
}

.action-btn:hover { color: var(--primary); border-color: var(--primary); }
.action-btn.delete:hover { color: var(--danger); border-color: var(--danger); }

/* ===== 代码反查输入行 ===== */
.code-lookup-row {
  display: flex;
  gap: 0.5rem;
}

.code-lookup-row .form-input { flex: 1; }

.lookup-btn {
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}

.lookup-btn:hover { border-color: var(--primary); background: var(--primary-light); }
.lookup-btn:disabled { opacity: 0.5; cursor: wait; }

.lookup-status {
  font-size: 0.75rem;
  margin-top: 0.25rem;
  min-height: 1em;
}
.lookup-status.loading { color: var(--info); }
.lookup-status.success { color: var(--success); }
.lookup-status.error { color: var(--danger); }

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .dashboard-charts { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; }
  .topbar { padding: 0.6rem 1rem; }
  .tab-content { padding: 1rem; }
  .net-worth-display { display: none; }
  .logo-text { font-size: 1rem; }
  .tabs { padding: 0.5rem 0.5rem 0; }
  .tab span { font-size: 0.8rem; }
}

@media (max-width: 480px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .settings-row { flex-direction: column; align-items: flex-start; }
  .theme-options { width: 100%; }
  .theme-option { flex: 1; text-align: center; }
}
