/* ────────────────────────────────────────
   Design Tokens — Dark (default)
──────────────────────────────────────── */
:root {
  --bg: #07091a;
  --bg-card: #0d1225;
  --bg-card-2: #121830;
  --bg-input: #1a2035;
  --border: #1e2d4a;
  --border-light: #2a3e60;
  --blue: #3b82f6;
  --blue-dim: #1d4ed8;
  --green: #10b981;
  --red: #ef4444;
  --yellow: #f59e0b;
  --purple: #8b5cf6;
  --text: #e2e8f0;
  --text-2: #94a3b8;
  --text-3: #64748b;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,.5);
  --transition: .2s ease;
  --primary: var(--blue);
}

/* ────────────────────────────────────────
   Design Tokens — Light
──────────────────────────────────────── */
[data-theme="light"] {
  --bg: #f0f2f8;
  --bg-card: #ffffff;
  --bg-card-2: #f5f7fc;
  --bg-input: #eef1f8;
  --border: #d4dbe8;
  --border-light: #b0bdd4;
  --blue: #2563eb;
  --blue-dim: #1d4ed8;
  --green: #059669;
  --red: #dc2626;
  --yellow: #d97706;
  --purple: #7c3aed;
  --text: #111827;
  --text-2: #374151;
  --text-3: #6b7280;
  --shadow: 0 4px 24px rgba(0,0,0,.10);
}

[data-theme="light"] .header {
  background: linear-gradient(90deg, #e8edf8 0%, #dde5f5 100%);
}

[data-theme="light"] thead th {
  background: rgba(0,0,0,.03);
}

[data-theme="light"] tbody tr:hover {
  background: rgba(0,0,0,.025);
}

[data-theme="light"] .modal-overlay {
  background: rgba(0,0,0,.45);
}

[data-theme="light"] .sellable-row td {
  background: rgba(5,150,105,.06) !important;
}

/* ────────────────────────────────────────
   Reset & Base
──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Inter', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}
a { color: var(--blue); text-decoration: none; }
button { cursor: pointer; border: none; outline: none; transition: var(--transition); }
input, select { outline: none; }

/* ────────────────────────────────────────
   Layout
──────────────────────────────────────── */
.container { max-width: 1400px; margin: 0 auto; padding: 0 24px; }

/* ────────────────────────────────────────
   Header
──────────────────────────────────────── */
.header {
  background: linear-gradient(90deg, #0d1225 0%, #111a35 100%);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  position: sticky; top: 0; z-index: 100;
}
.header-inner {
  max-width: 1400px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  height: 64px;
}
.logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 1.15rem; font-weight: 700; color: var(--text);
}
.logo-icon {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
}
.header-actions { display: flex; align-items: center; gap: 10px; }
.time-badge {
  font-size: .8rem; color: var(--text-2);
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 4px 12px; border-radius: 20px;
}

/* ────────────────────────────────────────
   Buttons
──────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: .85rem; font-weight: 500; transition: var(--transition);
}
.btn-primary {
  background: var(--blue); color: #fff;
}
.btn-primary:hover { background: var(--blue-dim); transform: translateY(-1px); }
.btn-success {
  background: var(--green); color: #fff;
}
.btn-success:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn-danger {
  background: transparent; color: var(--red);
  border: 1px solid var(--red);
}
.btn-danger:hover { background: rgba(239,68,68,.1); }
.btn-ghost {
  background: var(--bg-input); color: var(--text-2);
  border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: var(--blue); color: var(--blue); }
.btn-sm { padding: 5px 10px; font-size: .78rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none !important; }

/* ── Theme Toggle ── */
.theme-toggle {
  width: 38px; height: 22px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 11px;
  position: relative;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  flex-shrink: 0;
}
.theme-toggle::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 14px; height: 14px;
  background: var(--text-3);
  border-radius: 50%;
  transition: transform var(--transition), background var(--transition);
}
[data-theme="light"] .theme-toggle {
  background: #dde5f5;
  border-color: var(--border);
}
[data-theme="light"] .theme-toggle::after {
  transform: translateX(16px);
  background: var(--blue);
}
.theme-label {
  font-size: .78rem; color: var(--text-3);
  display: flex; align-items: center; gap: 6px;
  user-select: none; cursor: pointer;
}

/* ────────────────────────────────────────
   Summary Cards
──────────────────────────────────────── */
.summary-section { padding: 28px 0 0; }
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  position: relative; overflow: hidden;
  transition: var(--transition);
}
.summary-card:hover { border-color: var(--border-light); transform: translateY(-2px); box-shadow: var(--shadow); }
.summary-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
}
.card-blue::before  { background: linear-gradient(90deg, var(--blue), var(--purple)); }
.card-green::before { background: linear-gradient(90deg, var(--green), #059669); }
.card-yellow::before{ background: linear-gradient(90deg, var(--yellow), #d97706); }
.card-purple::before{ background: linear-gradient(90deg, var(--purple), var(--blue)); }

.card-label { font-size: .78rem; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; }
.card-value {
  font-size: 1.7rem; font-weight: 700;
  margin: 8px 0 4px; color: var(--text);
  font-variant-numeric: tabular-nums;
}
.card-sub { font-size: .8rem; color: var(--text-2); }
.card-icon {
  position: absolute; right: 20px; top: 50%; transform: translateY(-50%);
  font-size: 2.2rem; opacity: .08;
}

/* ────────────────────────────────────────
   Stats Row
──────────────────────────────────────── */
.stats-row {
  display: flex; gap: 12px; flex-wrap: wrap;
  margin: 16px 0 28px;
}
.stat-pill {
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: 30px;
  padding: 6px 16px;
  font-size: .82rem; color: var(--text-2);
  display: flex; align-items: center; gap: 8px;
}
.stat-pill strong { color: var(--text); }

/* ────────────────────────────────────────
   Tabs
──────────────────────────────────────── */
.tabs-bar {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--border);
  padding: 0;
  margin-bottom: 24px;
}
.tab-btn {
  padding: 12px 20px;
  background: none; color: var(--text-2);
  font-size: .9rem; font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  border-radius: 0;
  display: flex; align-items: center; gap: 8px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab-badge {
  background: var(--blue); color: #fff;
  font-size: .7rem; padding: 1px 7px;
  border-radius: 10px; font-weight: 600;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ────────────────────────────────────────
   Section Header
──────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.section-title { font-size: 1rem; font-weight: 600; }

/* ────────────────────────────────────────
   Fund Add Form
──────────────────────────────────────── */
.add-fund-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 24px;
}
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.form-group { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 140px; }
.form-label { font-size: .78rem; color: var(--text-2); }
.form-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 13px;
  font-size: .88rem; width: 100%;
  transition: var(--transition);
}
.form-input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.form-input::placeholder { color: var(--text-3); }

/* ────────────────────────────────────────
   Table
──────────────────────────────────────── */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
table {
  width: 100%; border-collapse: collapse;
  font-size: .85rem;
}
thead th {
  background: rgba(255,255,255,.02);
  color: var(--text-3); font-weight: 600;
  padding: 12px 16px; text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: .75rem; text-transform: uppercase; letter-spacing: .05em;
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid rgba(30,45,74,.5); transition: var(--transition); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,.025); }
tbody td { padding: 12px 16px; color: var(--text-2); vertical-align: middle; }
.cell-primary { color: var(--text); font-weight: 500; }

/* ────────────────────────────────────────
   Profit Rate Colors
──────────────────────────────────────── */
.profit-pos { color: var(--green); font-weight: 600; }
.profit-neg { color: var(--red); font-weight: 600; }
.profit-zero { color: var(--text-3); }
.sellable-row td { background: rgba(16,185,129,.04) !important; }
.sellable-badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(16,185,129,.15);
  color: var(--green); border-radius: 4px;
  padding: 2px 8px; font-size: .72rem; font-weight: 600;
}

/* ────────────────────────────────────────
   Status Badge
──────────────────────────────────────── */
.badge {
  display: inline-block; padding: 3px 10px;
  border-radius: 20px; font-size: .74rem; font-weight: 600;
}
.badge-holding { background: rgba(59,130,246,.15); color: var(--blue); }
.badge-sold    { background: rgba(100,116,139,.15); color: var(--text-3); }
.badge-active  { background: rgba(16,185,129,.15); color: var(--green); }
.badge-inactive{ background: rgba(100,116,139,.15); color: var(--text-3); }
.badge-success { background: rgba(16,185,129,.15); color: var(--green); }
.badge-primary { background: rgba(59,130,246,.15); color: var(--blue); }

/* ────────────────────────────────────────
   Filter Bar
──────────────────────────────────────── */
.filter-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.filter-select {
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text-2); border-radius: var(--radius-sm);
  padding: 7px 12px; font-size: .83rem;
  transition: var(--transition);
}
.filter-select:focus { border-color: var(--blue); }

/* ────────────────────────────────────────
   Empty State
──────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-3);
}
.empty-icon { font-size: 3rem; margin-bottom: 12px; opacity: .5; }
.empty-text { font-size: .9rem; }

/* ────────────────────────────────────────
   Modal
──────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7); backdrop-filter: blur(4px);
  z-index: 1000;
  display: none; align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 28px;
  width: 440px; max-width: 95vw;
  animation: modalIn .2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.95) translateY(10px); }
  to   { opacity: 1; transform: none; }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 22px;
}
.modal-title { font-size: 1.05rem; font-weight: 600; }
.modal-close {
  background: none; font-size: 1.3rem; color: var(--text-3);
  padding: 2px 6px; border-radius: 4px;
}
.modal-close:hover { color: var(--text); background: var(--bg-input); }
.modal-body { display: flex; flex-direction: column; gap: 16px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

/* ────────────────────────────────────────
   Toast
──────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 28px; right: 28px;
  z-index: 9999; display: flex; flex-direction: column; gap: 10px;
}
.toast {
  background: var(--bg-card-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 18px; font-size: .85rem; color: var(--text);
  box-shadow: var(--shadow);
  animation: toastIn .3s ease;
  display: flex; align-items: center; gap: 10px; min-width: 200px;
}
.toast-success { border-left: 3px solid var(--green); }
.toast-error   { border-left: 3px solid var(--red); }
.toast-info    { border-left: 3px solid var(--blue); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: none; }
}

/* ────────────────────────────────────────
   Loading Spinner
──────────────────────────────────────── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.15);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ────────────────────────────────────────
   Daily Profit Panel
──────────────────────────────────────── */
.daily-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow: hidden;
  transition: var(--transition);
}
.daily-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid transparent;
  transition: var(--transition);
}
.daily-header:hover { background: rgba(255,255,255,.02); }
.daily-panel.has-data .daily-header { border-bottom-color: var(--border); }
.daily-icon { font-size: 1.1rem; }
.daily-title { font-weight: 600; font-size: .95rem; }
.daily-time { font-size: .75rem; color: var(--text-3); }
.daily-total { font-size: 1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.daily-rate  { font-size: .85rem; font-weight: 600; }
.daily-toggle { font-size: .9rem; color: var(--text-3); transition: var(--transition); }

.daily-body { padding: 16px 20px; }
.daily-funds-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.daily-fund-card {
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 6px;
  transition: var(--transition);
}
.daily-fund-card:hover { border-color: var(--border-light); }
.daily-fund-name  { font-size: .88rem; font-weight: 600; color: var(--text); }
.daily-fund-nav   { font-size: .85rem; color: var(--text-2); }
.daily-fund-meta  { display: flex; justify-content: space-between; }
.daily-fund-change{ font-size: 1.05rem; font-weight: 700; margin-top: 4px; }
.daily-fund-rate  { font-size: .8rem; font-weight: 600; }

/* ────────────────────────────────────────
   Auto-refresh indicator
──────────────────────────────────────── */
.refresh-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  margin-left: 4px;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%,100% { opacity: 1; transform: scale(1); }
  50% { opacity: .4; transform: scale(.7); }
}

/* ────────────────────────────────────────
   Sortable Table Headers
──────────────────────────────────────── */
th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  transition: background-color 0.2s;
}
th.sortable:hover {
  background-color: rgba(255,255,255,.05);
}
th.sortable::after {
  content: '↕';
  font-size: 0.7rem;
  margin-left: 4px;
  color: var(--text-3);
  vertical-align: middle;
}
th.sort-asc::after { content: '↑'; color: var(--primary); }
th.sort-desc::after { content: '↓'; color: var(--primary); }

/* ────────────────────────────────────────
   Responsive
──────────────────────────────────────── */
@media (max-width: 900px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { flex-direction: column; }
}
@media (max-width: 600px) {
  .summary-grid { grid-template-columns: 1fr; }
  .container { padding: 0 12px; }
}
