/* Apple HIG / iOS Design System for 简财 PWA */

:root {
  --bg-grouped: #F2F2F7;
  --bg-card: #FFFFFF;
  --bg-elevated: #FFFFFF;
  --bg-fill: rgba(120, 120, 128, 0.12);
  --bg-fill-strong: rgba(120, 120, 128, 0.20);
  --bg-glass: rgba(249, 249, 251, 0.84);

  --text-primary: #000000;
  --text-secondary: #6C6C70;
  --text-tertiary: #AEAEB2;

  --separator: rgba(60, 60, 67, 0.12);
  --accent: #007AFF;
  --accent-soft: rgba(0, 122, 255, 0.12);
  --red: #FF3B30;
  --red-soft: rgba(255, 59, 48, 0.12);
  --green: #34C759;
  --green-soft: rgba(52, 199, 89, 0.14);
  --orange: #FF9500;
  --orange-soft: rgba(255, 149, 0, 0.14);
  --pos-color: var(--green);
  --neg-color: var(--red);

  --pos-color: var(--green);
  --neg-color: var(--red);

  --radius-card: 16px;
  --radius-sheet: 24px;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.04);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tab-height: 60px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-grouped: #000000;
    --bg-card: #1C1C1E;
    --bg-elevated: #2C2C2E;
    --bg-fill: rgba(120, 120, 128, 0.24);
    --bg-fill-strong: rgba(120, 120, 128, 0.36);
    --bg-glass: rgba(28, 28, 30, 0.84);

    --text-primary: #FFFFFF;
    --text-secondary: #98989F;
    --text-tertiary: #636366;

    --separator: rgba(84, 84, 88, 0.52);
    --accent: #0A84FF;
    --accent-soft: rgba(10, 132, 255, 0.20);
    --red: #FF453A;
    --red-soft: rgba(255, 69, 58, 0.20);
    --green: #30D158;
    --green-soft: rgba(48, 209, 88, 0.20);
    --orange: #FF9F0A;
    --orange-soft: rgba(255, 159, 10, 0.20);

    --shadow-card: 0 1px 4px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --bg-grouped: #000000;
  --bg-card: #1C1C1E;
  --bg-elevated: #2C2C2E;
  --bg-fill: rgba(120, 120, 128, 0.24);
  --bg-fill-strong: rgba(120, 120, 128, 0.36);
  --bg-glass: rgba(28, 28, 30, 0.84);

  --text-primary: #FFFFFF;
  --text-secondary: #98989F;
  --text-tertiary: #636366;

  --separator: rgba(84, 84, 88, 0.52);
  --accent: #0A84FF;
  --accent-soft: rgba(10, 132, 255, 0.20);
  --red: #FF453A;
  --red-soft: rgba(255, 69, 58, 0.20);
  --green: #30D158;
  --green-soft: rgba(48, 209, 88, 0.20);
  --orange: #FF9F0A;
  --orange-soft: rgba(255, 159, 10, 0.20);

  --shadow-card: 0 1px 4px rgba(0, 0, 0, 0.35);
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg-grouped);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "PingFang SC", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

button {
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
}

:root[data-color-scheme="cn"] {
  --pos-color: var(--red);
  --neg-color: var(--green);
}

.hidden { display: none !important; }
.icon { width: 18px; height: 18px; flex-shrink: 0; display: inline-block; }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--pos-color); }
.neg { color: var(--neg-color); }
.muted { color: var(--text-secondary); }

/* App Shell */
.app-shell {
  max-width: 540px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--tab-height) + var(--safe-bottom) + 28px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 8px;
}

.topbar-title {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-card);
  transition: transform 0.14s ease, opacity 0.14s ease;
}

.icon-btn:active { transform: scale(0.92); opacity: 0.75; }
.icon-btn .icon { width: 18px; height: 18px; }
.icon-btn.spinning .icon { animation: spin 0.9s linear infinite; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

.pill-btn {
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  box-shadow: var(--shadow-card);
}

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

.pill-btn:active { opacity: 0.78; }
.pill-btn .icon { width: 15px; height: 15px; }

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  padding: 16px;
  box-shadow: var(--shadow-card);
  margin-bottom: 14px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
}

.card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.card-sub {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Hero Card */
.hero-card {
  background: linear-gradient(135deg, #007AFF 0%, #30B0C7 100%);
  color: #FFFFFF;
  border-radius: 20px;
  padding: 20px;
  margin-bottom: 14px;
  box-shadow: 0 8px 24px rgba(0, 122, 255, 0.22);
}

.hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  opacity: 0.9;
  margin-bottom: 6px;
}

.hero-cur-btn {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  backdrop-filter: blur(8px);
}

.hero-amount {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.8px;
  line-height: 1.15;
  margin-bottom: 14px;
}

.hero-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.22);
}

.hero-metric-label {
  font-size: 11px;
  opacity: 0.82;
  margin-bottom: 3px;
}

.hero-metric-val {
  font-size: 14px;
  font-weight: 600;
}

.hero-metric-sub {
  font-size: 11px;
  opacity: 0.85;
  margin-top: 2px;
}

/* Segmented Control */
.segmented {
  display: inline-flex;
  background: var(--bg-fill);
  padding: 2px;
  border-radius: 9px;
  gap: 2px;
}

.segmented button {
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 7px;
  color: var(--text-secondary);
  transition: background 0.16s ease, color 0.16s ease;
}

.segmented button.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* Charts */
.donut-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
}

.donut-svg-box {
  position: relative;
  width: 148px;
  height: 148px;
  flex-shrink: 0;
}

.donut-svg { width: 100%; height: 100%; display: block; }

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
  padding: 0 16px;
}

.donut-center-label {
  font-size: 11px;
  color: var(--text-secondary);
}

.donut-center-val {
  font-size: 14px;
  font-weight: 700;
  margin-top: 2px;
}

.donut-legend {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

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

.legend-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.legend-pct {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.empty-chart {
  text-align: center;
  padding: 28px 12px;
  font-size: 13px;
  color: var(--text-secondary);
}

.trend-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 3px;
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 5px;
}
.swatch-primary { background: var(--accent); }
.swatch-cost { background: var(--text-tertiary); }

.trend-svg { width: 100%; height: 156px; display: block; }
.chart-axis-text {
  font-size: 10px;
  fill: var(--text-tertiary);
}

/* List / Rows */
.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 6px 4px 8px;
}

.list-card {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  margin-bottom: 14px;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  gap: 12px;
  position: relative;
  width: 100%;
  text-align: left;
}

.list-row + .list-row::before {
  content: '';
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 0.5px;
  background: var(--separator);
}

.list-row.clickable:active {
  background: var(--bg-fill);
}

.asset-badge {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: -0.3px;
}

.row-main {
  flex: 1;
  min-width: 0;
}

.row-title {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tag {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--bg-fill);
  color: var(--text-secondary);
}

.row-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-right {
  text-align: right;
  flex-shrink: 0;
}

.row-val {
  font-size: 15px;
  font-weight: 600;
}

.row-pnl {
  font-size: 12px;
  margin-top: 3px;
}

/* Rebalance & Plan */
.rebalance-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.input-box {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border-radius: 11px;
  border: 1px solid var(--separator);
  background: var(--bg-grouped);
  font-size: 15px;
  outline: none;
}

.input-box:focus {
  border-color: var(--accent);
}

.progress-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-fill);
  overflow: hidden;
  margin-top: 6px;
  position: relative;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
}

.rebalance-item {
  padding: 12px 0;
  border-bottom: 0.5px solid var(--separator);
}
.rebalance-item:last-child { border-bottom: none; padding-bottom: 0; }

.rebalance-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  font-weight: 600;
}

.rebalance-buy-chip {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

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

.template-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chip-btn {
  padding: 7px 12px;
  border-radius: 10px;
  background: var(--bg-fill);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}
.chip-btn:active { opacity: 0.75; }

/* Compound Simulator */
.sim-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.field-label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 5px;
  font-weight: 500;
}

.sim-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: var(--bg-grouped);
  padding: 12px;
  border-radius: 12px;
  margin-bottom: 12px;
  text-align: center;
}

.sim-summary-label { font-size: 11px; color: var(--text-secondary); }
.sim-summary-val { font-size: 14px; font-weight: 700; margin-top: 3px; }

/* Settings */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  gap: 12px;
  position: relative;
}
.setting-row + .setting-row::before {
  content: '';
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 0.5px;
  background: var(--separator);
}

.btn-full {
  width: 100%;
  height: 44px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--bg-fill); color: var(--text-primary); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-full:active { opacity: 0.8; }

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Bottom Tab Bar */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--tab-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-glass);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
  z-index: 50;
}

.tabbar-inner {
  max-width: 540px;
  height: var(--tab-height);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
}

.tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 600;
}

.tab-btn .icon { width: 22px; height: 22px; }
.tab-btn.active { color: var(--accent); }

/* Bottom Sheet Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  width: 100%;
  max-width: 540px;
  max-height: 90dvh;
  background: var(--bg-card);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  padding: 16px 18px calc(var(--safe-bottom) + 20px);
  overflow-y: auto;
  transform: translateY(24px);
  transition: transform 0.22s ease;
}

.modal-backdrop.open .sheet {
  transform: translateY(0);
}

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

.sheet-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.form-group { margin-bottom: 12px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.trade-list-mini {
  margin-top: 10px;
  border-top: 0.5px solid var(--separator);
}

.trade-mini-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--separator);
  font-size: 13px;
  gap: 8px;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-height) + var(--safe-bottom) + 18px);
  transform: translateX(-50%) translateY(12px);
  background: rgba(28, 28, 30, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 200;
  max-width: 90vw;
  text-align: center;
}

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

/* v2.0 Additions: Alerts, Signals, DCA History, News */
.alert-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--orange-soft);
  color: var(--orange);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
  width: 100%;
  text-align: left;
}

.hero-subline {
  font-size: 12px;
  opacity: 0.88;
  margin-top: -8px;
  margin-bottom: 12px;
}

.sig-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.sig-badge.strong_buy { background: var(--green-soft); color: var(--green); }
.sig-badge.buy { background: var(--accent-soft); color: var(--accent); }
.sig-badge.hold, .sig-badge.watch { background: var(--bg-fill); color: var(--text-secondary); }
.sig-badge.caution, .sig-badge.maturity { background: var(--orange-soft); color: var(--orange); }
.sig-badge.sell { background: var(--red-soft); color: var(--red); }

.signal-card-row {
  padding: 13px 16px;
  position: relative;
}
.signal-card-row + .signal-card-row::before {
  content: '';
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 0.5px;
  background: var(--separator);
}
.signal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
}
.signal-reason {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.45;
}
.signal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  gap: 8px;
}
.mini-btn {
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-fill);
  color: var(--text-primary);
}
.mini-btn.primary, .mini-btn.accent { background: var(--accent-soft); color: var(--accent); }
.mini-btn.danger { background: var(--red-soft); color: var(--red); }

.signal-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.signal-strong_buy { background: var(--green-soft); color: var(--green); }
.signal-buy { background: var(--accent-soft); color: var(--accent); }
.signal-hold, .signal-watch { background: var(--bg-fill); color: var(--text-secondary); }
.signal-caution, .signal-maturity { background: var(--orange-soft); color: var(--orange); }
.signal-sell { background: var(--red-soft); color: var(--red); }

.signal-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.dca-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-grouped);
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 12px;
}

.timeline-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--separator);
  gap: 10px;
}
.timeline-row:last-child { border-bottom: none; padding-bottom: 0; }

.hero-sub-bar {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  opacity: 0.88;
  margin-top: -8px;
  margin-bottom: 12px;
}

.drawdown-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.drawdown-box {
  background: var(--bg-grouped);
  border-radius: 12px;
  padding: 12px;
}
.drawdown-box.alert {
  background: var(--green-soft);
}

.news-row {
  display: block;
  padding: 12px 16px;
  text-decoration: none;
  color: inherit;
  position: relative;
}
.news-row + .news-row::before {
  content: '';
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 0.5px;
  background: var(--separator);
}
.news-title {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  margin-bottom: 4px;
}
.news-meta {
  font-size: 11px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.dca-countdown,
.dca-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-grouped);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
  gap: 10px;
}

.hero-sub-bar {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  opacity: 0.88;
  margin-top: -8px;
  margin-bottom: 12px;
}

.signal-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.signal-strong_buy { background: var(--green-soft); color: var(--green); }
.signal-buy { background: var(--accent-soft); color: var(--accent); }
.signal-hold, .signal-watch { background: var(--bg-fill); color: var(--text-secondary); }
.signal-caution, .signal-maturity { background: var(--orange-soft); color: var(--orange); }
.signal-sell { background: var(--red-soft); color: var(--red); }

.signal-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
}

.mini-btn.accent { background: var(--accent-soft); color: var(--accent); }

.timeline-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--separator);
  gap: 10px;
}
.timeline-row:last-child { border-bottom: none; padding-bottom: 0; }

@media (max-width: 390px) {
  .donut-wrap { flex-direction: column; }
  .hero-amount { font-size: 28px; }
}
