/* ============================================================
   base.css — Light Financial Dashboard Design System
   全局设计令牌 + CSS Reset + 通用组件
   ============================================================ */

/* ---------- CSS Custom Properties ---------- */
:root {
  /* Colors — Light Theme */
  --bg-primary: #f3f4f6;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f9fafb;
  --border: #e5e7eb;
  --border-light: #ffffff;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --accent: #d4a00a;
  --accent-blue: #3b82f6;
  --up: #dc2626;
  --up-bg: rgba(255,0,0,0.18);
  --down: #15803d;
  --down-bg: rgba(0,200,80,0.15);
  --flat: #2563eb;
  --flat-bg: rgba(30,90,240,0.15);
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d4a00a;
  --info: #3b82f6;

  /* Typography */
  --font-sans: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", "Fira Code", "Consolas", monospace;

  /* Spacing (8px grid) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 10px;
  --space-4: 14px;
  --space-5: 18px;
  --space-6: 32px;
  --space-7: 48px;

  /* Radii */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
  --shadow: 0 4px 12px rgba(0,0,0,.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.1);
  --glow-accent: 0 0 16px rgba(212,160,10,.15);

  /* Transitions */
  --ease: cubic-bezier(.4,0,.2,1);
  --fast: .15s;
  --normal: .25s;
  --slow: .4s;
}

/* ---------- CSS Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; font-size: 16px; }
body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}
a { color: var(--accent-blue); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; color: inherit; }
h1,h2,h3,h4,h5,h6 { font-weight: 600; line-height: 1.3; }
::selection { background: rgba(59,130,246,.2); color: #111827; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }
::-webkit-scrollbar-corner { background: transparent; }

/* ---------- Typography ---------- */
.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 18px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; cursor: pointer; transition: all var(--fast) var(--ease);
  background: var(--bg-secondary); color: var(--text-primary);
  white-space: nowrap; user-select: none; text-decoration: none;
  min-height: 38px; min-width: 38px;
}
.btn:hover { background: var(--bg-tertiary); border-color: #d1d5db; text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent-blue); border-color: var(--accent-blue); color: #fff; }
.btn-primary:hover { background: #2563eb; border-color: #2563eb; box-shadow: 0 0 12px rgba(59,130,246,.25); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; box-shadow: 0 0 12px rgba(220,38,38,.25); }
.btn-warning { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-warning:hover { background: #b8860b; border-color: #b8860b; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.btn-sm { padding: 5px 12px; font-size: 12px; min-height: 30px; min-width: 30px; }
.btn-lg { padding: 12px 28px; font-size: 15px; min-height: 48px; }
.btn-block { display: flex; width: 100%; }
.btn:disabled, .btn.disabled { opacity: .5; pointer-events: none; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex; align-items: center; gap: var(--space-3);
  margin-bottom: var(--space-4); padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border-light);
  font-size: 15px; font-weight: 600; color: var(--text-primary);
}
.card-header::before {
  content: ''; display: inline-block;
  width: 3px; height: 18px; border-radius: 2px;
  background: var(--accent);
}

/* ---------- Forms ---------- */
.form-group { margin-bottom: var(--space-4); }
.form-label { display: block; margin-bottom: var(--space-2); font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.form-input, .form-select {
  width: 100%; height: 42px; padding: 0 14px;
  background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px; color: var(--text-primary);
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
  outline: none;
}
.form-input:focus, .form-select:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}
.form-input::placeholder { color: var(--text-muted); }
.form-input[readonly] { background: var(--bg-tertiary); color: var(--text-secondary); }
.form-select {
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236b7280'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 36px; cursor: pointer;
}
textarea.form-input { height: auto; padding: 12px 14px; resize: vertical; min-height: 80px; }

/* Form row (inline fields) */
.form-row { display: flex; gap: var(--space-3); align-items: flex-end; }
.form-row > .form-group { flex: 1; }

/* ---------- Toggle Switch ---------- */
.toggle-switch {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  font-size: 13px; color: var(--text-secondary); user-select: none;
}
.toggle-switch input { display: none; }
.toggle-track {
  width: 38px; height: 22px; border-radius: 11px;
  background: #d1d5db; border: 1px solid #d1d5db;
  position: relative; transition: all var(--fast) var(--ease); flex-shrink: 0;
}
.toggle-track::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: all var(--fast) var(--ease);
}
.toggle-switch input:checked + .toggle-track {
  background: var(--accent-blue); border-color: var(--accent-blue);
}
.toggle-switch input:checked + .toggle-track::after {
  background: #fff; transform: translateX(16px);
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 12px;
  font-size: 11px; font-weight: 600; line-height: 1.8;
}
.badge-up { background: var(--up-bg); color: var(--up); }
.badge-down { background: var(--down-bg); color: var(--down); }
.badge-flat { background: var(--flat-bg); color: var(--flat); }
.badge-admin { background: rgba(212,160,10,.1); color: #b8860b; }
.badge-user { background: var(--bg-tertiary); color: var(--text-secondary); }

/* ---------- Toast ---------- */
.toast-container {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 2000; display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 24px; border-radius: var(--radius-sm); color: #fff; font-size: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  animation: toastIn .25s var(--ease), toastOut .25s 2.6s var(--ease) forwards;
  white-space: nowrap; pointer-events: auto;
}
.toast-success { background: #16a34a; }
.toast-error { background: #dc2626; }
.toast-info { background: var(--accent-blue); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-8px); } }

/* ---------- Data Table ---------- */
.table-wrapper {
  overflow-x: auto; border-radius: var(--radius);
  border: 1px solid var(--border);
}
.data-table {
  width: 100%; border-collapse: collapse;
  font-size: 14px; background: var(--bg-secondary);
}
.data-table thead th {
  background: var(--bg-tertiary); color: var(--text-secondary);
  padding: 10px 12px; text-align: center; white-space: nowrap;
  font-weight: 500; font-size: 12px; text-transform: uppercase;
  letter-spacing: .04em; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1;
}
.data-table tbody td {
  padding: 9px 12px; text-align: center; white-space: nowrap;
  border-bottom: 1px solid var(--border-light);
  transition: background var(--fast) var(--ease);
}
.data-table tbody tr:hover td {
  background: rgba(0,0,0,.02);
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .num { font-size: .95em; }
.empty-row td {
  text-align: center; color: var(--text-muted);
  padding: 40px 20px !important; font-size: 14px;
}

/* Row states */
.row-up td { background: var(--up-bg); }
.row-down td { background: var(--down-bg); }
.row-flat td { background: var(--flat-bg); }
.row-up td:first-child { border-left: 3px solid var(--up); }
.row-down td:first-child { border-left: 3px solid var(--down); }
.row-flat td:first-child { border-left: 3px solid var(--flat); }

/* Pct cell — yellow bold */
.pct-cell {
  font-family: var(--font-mono); font-weight: 700; color: #b8860b;
}

/* ---------- Section Headers ---------- */
.section-header {
  display: flex; align-items: center; gap: var(--space-3);
  margin-bottom: var(--space-3); padding-left: var(--space-3);
  font-size: 15px; font-weight: 600; color: var(--text-primary);
}
.section-header::before {
  content: ''; width: 3px; height: 20px; border-radius: 2px; flex-shrink: 0;
}
.section-stock::before { background: var(--accent-blue); }
.section-watch::before { background: var(--accent); }
.section-fund::before { background: var(--down); }

/* ---------- Modal Overlay ---------- */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.4); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  justify-content: center; align-items: flex-start; padding: 10vh 0 40px;
  overflow-y: auto;
}
.modal-overlay.show { display: flex; }
.modal-content {
  width: 90vw; max-width: 480px;
  animation: modalIn .25s var(--ease);
}
.modal-box {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 28px;
  box-shadow: var(--shadow-lg); margin-bottom: 20px;
}
.modal-box h3 { margin: 0 0 20px; font-size: 16px; color: var(--text-primary); }
.modal-body { margin-bottom: 4px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(-16px) scale(.97); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* Confirm dialog */
.confirm-overlay {
  display: none; position: fixed; inset: 0; z-index: 1100;
  justify-content: center; align-items: flex-start; padding-top: 22vh;
  background: rgba(0,0,0,.4); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.confirm-overlay.show { display: flex; }
.confirm-overlay .modal-box { max-width: 380px; text-align: center; }
.confirm-overlay .modal-box p { margin-bottom: 20px; font-size: 14px; color: var(--text-secondary); }

/* ---------- Action Buttons (table) ---------- */
.action-btn {
  display: inline-block; padding: 3px 14px; border-radius: 20px;
  font-size: 12px; cursor: pointer; text-decoration: none;
  transition: all var(--fast) var(--ease); border: 1px solid transparent;
  font-weight: 500; line-height: 1.8;
}
.action-btn + .action-btn { margin-left: 4px; }
.action-btn-edit { background: rgba(59,130,246,.08); color: var(--accent-blue); border-color: rgba(59,130,246,.15); }
.action-btn-edit:hover { background: var(--accent-blue); color: #fff; }
.action-btn-del { background: rgba(220,38,38,.08); color: var(--danger); border-color: rgba(220,38,38,.15); }
.action-btn-del:hover { background: var(--danger); color: #fff; }
.action-btn-view { background: rgba(21,128,61,.08); color: var(--down); border-color: rgba(21,128,61,.15); }
.action-btn-view:hover { background: var(--down); color: #fff; }

/* ---------- Animation Keyframes ---------- */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

/* Staggered card reveal */
.stagger-1 { animation: fadeInUp .4s var(--ease) both; animation-delay: .05s; }
.stagger-2 { animation: fadeInUp .4s var(--ease) both; animation-delay: .1s; }
.stagger-3 { animation: fadeInUp .4s var(--ease) both; animation-delay: .15s; }
.stagger-4 { animation: fadeInUp .4s var(--ease) both; animation-delay: .2s; }
.stagger-5 { animation: fadeInUp .4s var(--ease) both; animation-delay: .25s; }
.stagger-6 { animation: fadeInUp .4s var(--ease) both; animation-delay: .3s; }

/* ---------- Utility Classes ---------- */
.text-up { color: var(--up); }
.text-down { color: var(--down); }
.text-flat { color: var(--flat); }
.text-mono { font-family: var(--font-mono); }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-bold { font-weight: 700; }
.hidden { display: none !important; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }

/* Hide scrollbar but keep scroll */
.hide-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
.hide-scrollbar::-webkit-scrollbar { display: none; }
