/* =========================================================
   熊熊币大作战 — iOS-native shell (原生骨架 + 熊熊个性)
   Pass 1: app shell + Dashboard. Light + dark, safe-area aware.
   ========================================================= */

/* 视觉隐藏但保留在 DOM 中（file input 在 iOS 上必须可被渲染，不能用 hidden 属性） */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

:root {
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Microsoft YaHei", system-ui, sans-serif;
  --font-round: ui-rounded, "SF Pro Rounded", -apple-system, "PingFang SC",
    system-ui, sans-serif;

  /* 熊熊蜂蜜琥珀主色 */
  --bear: #e0911b;
  --bear-soft: rgba(224, 145, 27, 0.14);
  --bear-deep: #a8650f;

  /* warm light theme */
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #faf7f0;
  --ink: #1d1b16;
  --muted: #8c8576;
  --faint: #b4ac9c;
  --line: rgba(40, 32, 16, 0.09);
  --hairline: rgba(40, 32, 16, 0.14);

  --pos: #1f9d57;
  --neg: #d2483a;
  --warn: #d98a12;

  --bar-bg: rgba(244, 241, 234, 0.82);
  --shadow: 0 1px 2px rgba(30, 24, 10, 0.05), 0 8px 24px rgba(30, 24, 10, 0.05);

  --r-card: 18px;
  --r-pill: 999px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 52px;

  /* legacy aliases still referenced by table/settings markup */
  --panel: var(--surface);
  --input: #fff7df;
}

/* 暗色变量：跟随系统（除非用户强制明亮）+ 用户强制夜晚 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bear: #f3a93a;
    --bear-soft: rgba(243, 169, 58, 0.16);
    --bear-deep: #f7c074;

    --bg: #16130e;
    --surface: #211c15;
    --surface-2: #2a241b;
    --ink: #f4efe3;
    --muted: #9c9384;
    --faint: #6f6757;
    --line: rgba(255, 255, 255, 0.09);
    --hairline: rgba(255, 255, 255, 0.14);

    --pos: #3ad17e;
    --neg: #ff6b5c;
    --warn: #f3b03a;

    --bar-bg: rgba(22, 19, 14, 0.8);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
    --input: #3a3322;
  }
}
:root[data-theme="dark"] {
  --bear: #f3a93a;
  --bear-soft: rgba(243, 169, 58, 0.16);
  --bear-deep: #f7c074;

  --bg: #16130e;
  --surface: #211c15;
  --surface-2: #2a241b;
  --ink: #f4efe3;
  --muted: #9c9384;
  --faint: #6f6757;
  --line: rgba(255, 255, 255, 0.09);
  --hairline: rgba(255, 255, 255, 0.14);

  --pos: #3ad17e;
  --neg: #ff6b5c;
  --warn: #f3b03a;

  --bar-bg: rgba(22, 19, 14, 0.8);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
  --input: #3a3322;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

body {
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: -0.01em;
  overscroll-behavior-y: none;
}

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

h1,
h2,
h3,
p {
  margin: 0;
}

.tnum {
  font-variant-numeric: tabular-nums;
}

/* ---------- Top bar / large title ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: calc(var(--safe-top) + 10px) 20px 14px;
  background: linear-gradient(180deg, rgba(224, 145, 27, 0.09), rgba(224, 145, 27, 0) 70%), var(--bar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 0.5px solid var(--hairline);
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
}

.brand {
  font-family: var(--font-round);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.02em;
}

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

.cur-select {
  height: 32px;
  border: 0.5px solid var(--hairline);
  border-radius: var(--r-pill);
  padding: 0 26px 0 12px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238c8576' d='M6 8.5 2.5 5h7z'/%3E%3C/svg%3E") no-repeat right 9px center;
  -webkit-appearance: none;
  appearance: none;
  font-size: 14px;
  font-weight: 600;
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 0.5px solid var(--hairline);
  border-radius: var(--r-pill);
  background: var(--surface);
  font-size: 16px;
  cursor: pointer;
}

.pill-btn {
  height: 32px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--bear);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.icon-btn:active,
.pill-btn:active {
  transform: scale(0.94);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 13px;
  padding-top: 6px;
}

.title-avatar {
  width: 72px;
  height: 72px;
  object-fit: contain;
  flex: 0 0 auto;
}

.title-avatar.brand-avatar--fallback {
  font-size: 24px;
  border: 0;
}

.app-title {
  font-family: var(--font-round);
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.title-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.update-note {
  color: var(--muted);
  font-size: 12px;
}

.largetitle h1 {
  font-family: var(--font-round);
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.largetitle-sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- Main scroll area ---------- */

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 28px);
}

.view {
  display: none;
}

.active-view {
  display: block;
  animation: viewin 0.26s ease;
}

@keyframes viewin {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ---------- Bottom tab bar ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  padding-bottom: var(--safe-bottom);
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--hairline);
}

.tabbtn {
  flex: 1;
  height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  transition: color 0.15s;
}

.tabbtn .ti {
  font-size: 21px;
  line-height: 1;
  filter: grayscale(1) opacity(0.55);
  transition: filter 0.15s, transform 0.15s;
}

.ti-img {
  width: 27px;
  height: 27px;
  object-fit: contain;
}

.tabbtn .tl {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0;
}

.tabbtn.active {
  color: var(--bear);
}

.tabbtn.active .ti {
  filter: none;
  transform: translateY(-1px) scale(1.06);
}

.tabbtn:active .ti {
  transform: scale(0.9);
}

/* ---------- More sheet ---------- */

.more-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.32);
  opacity: 0;
  transition: opacity 0.25s;
}

.more-backdrop.open {
  opacity: 1;
}

.more-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 51;
  padding: 6px 14px calc(var(--safe-bottom) + 18px);
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.22);
  transform: translateY(110%);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
}

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

.sheet-grip {
  width: 38px;
  height: 5px;
  margin: 8px auto 6px;
  border-radius: 3px;
  background: var(--hairline);
}

.sheet-title {
  font-family: var(--font-round);
  font-size: 20px;
  font-weight: 800;
  padding: 4px 6px 12px;
}

.sheet-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 12px;
  border: 0;
  border-top: 0.5px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-size: 16px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.sheet-item .si {
  font-size: 20px;
}

.sheet-item .chev {
  margin-left: auto;
  color: var(--faint);
  font-size: 22px;
}

.sheet-item:active {
  background: var(--surface-2);
}

/* ---------- Dashboard metric cards ---------- */

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 8px;
}

.metric {
  background: var(--surface);
  border-radius: var(--r-card);
  padding: 16px;
  box-shadow: var(--shadow);
}

.metric label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  opacity: 0.92;
  color: var(--muted);
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-family: var(--font-round);
  font-size: 23px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.metric span {
  display: block;
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}

@media (min-width: 600px) {
  .metric-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ---------- Bands (grouped sections) ---------- */

.band {
  margin-top: 22px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 0 4px;
}

.section-head h2 {
  font-family: var(--font-round);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.section-head p {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 10px;
}

.visual-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 600px) {
  .visual-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.visual-grid > div,
.forecast-layout,
.breakdown-grid > div {
  background: var(--surface);
  border-radius: var(--r-card);
  padding: 16px;
  box-shadow: var(--shadow);
}

.forecast-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  overflow: hidden;
}

@media (min-width: 900px) {
  .forecast-layout {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    align-items: start;
  }
}

.breakdown-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 700px) {
  .breakdown-grid {
    grid-template-columns: 1.25fr 1fr;
  }
}

canvas {
  width: 100%;
  max-width: 460px;
  height: 240px;
}

#forecastCanvas {
  max-width: none;
  height: auto;
}

#forecastTable {
  overflow-x: auto;
}

#forecastTable table {
  min-width: 560px;
}

#forecastTable th,
#forecastTable td {
  white-space: nowrap;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

/* ---------- Insights ---------- */

.insight-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 600px) {
  .insight-list {
    grid-template-columns: repeat(3, 1fr);
  }
}

.insight {
  background: var(--surface);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  border-left: 3px solid var(--pos);
}

.insight.warn {
  border-left-color: var(--warn);
}

.insight.danger {
  border-left-color: var(--neg);
}

.insight strong {
  display: block;
  margin-bottom: 4px;
  font-weight: 700;
}

.insight p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

/* ---------- Data tables (Assets / Holdings / etc.) ---------- */

.data-table {
  overflow-x: auto;
  background: var(--surface);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

.compact-table {
  overflow-x: auto;
}

.compact-table table {
  min-width: 0;
}

.compact-table th,
.compact-table td {
  font-size: 12px;
  padding: 8px 9px;
}

th,
td {
  border-bottom: 0.5px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  text-align: center;
  z-index: 1;
}

tr:last-child td {
  border-bottom: 0;
}

td input,
td select {
  width: 100%;
  min-width: 78px;
  border: 0.5px solid var(--hairline);
  border-radius: 8px;
  padding: 7px 8px;
  background: var(--input);
}

td.output {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

/* ---------- AI summary ---------- */

.summary-box {
  width: 100%;
  min-height: 60vh;
  border: 0.5px solid var(--hairline);
  border-radius: var(--r-card);
  padding: 16px;
  background: var(--surface);
  color: var(--ink);
  line-height: 1.6;
  font-size: 14px;
  resize: vertical;
}

/* ---------- Settings ---------- */

.settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

@media (min-width: 720px) {
  .settings-grid {
    grid-template-columns: minmax(280px, 420px) minmax(280px, 1fr);
  }
}

.settings-panel {
  background: var(--surface);
  border-radius: var(--r-card);
  padding: 6px 16px;
  box-shadow: var(--shadow);
}

.settings-panel h3 {
  color: var(--ink);
  padding-top: 12px;
}

.rates-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.rates-head h3 {
  padding-top: 12px;
}

.settings-row {
  display: grid;
  grid-template-columns: 1fr 150px;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 0.5px solid var(--line);
}

.settings-row:last-child {
  border-bottom: 0;
}

.settings-row label {
  color: var(--muted);
  font-size: 14px;
}

.settings-row input,
.settings-row select {
  border: 0.5px solid var(--hairline);
  border-radius: 8px;
  padding: 8px;
  background: var(--input);
}

/* ---------- Section heads with add buttons ---------- */

.view > .section-head .secondary-btn {
  height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--bear-soft);
  color: var(--bear-deep);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.secondary-btn,
.primary-btn,
.light-btn {
  border: 0.5px solid var(--hairline);
  border-radius: var(--r-pill);
  padding: 7px 14px;
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
}

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

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

/* ---------- 数据上传/备份：苹果风全宽按钮 ---------- */
.settings-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 4px 0 18px;
}
.settings-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 50px;
  padding: 0 16px;
  border: 0.5px solid var(--hairline);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.1s ease;
}
.action-btn:active {
  transform: scale(0.985);
}
.action-btn-ic {
  font-size: 17px;
  line-height: 1;
}
.action-btn--primary {
  border-color: transparent;
  background: linear-gradient(155deg, var(--bear) 0%, var(--bear-deep) 100%);
  color: #fff;
  box-shadow: 0 8px 22px rgba(224, 145, 27, 0.26);
}
.action-btn--danger {
  color: var(--neg);
}
.rates-note {
  margin: 14px 2px 4px;
  color: var(--muted);
  font-size: 12px;
}

/* ---------- Capture preview (kept from prototype) ---------- */

.is-capturing .tabbar,
.is-capturing .topbar-actions,
.is-capturing .more-sheet,
.is-capturing .more-backdrop,
.is-capturing [data-add],
.is-capturing #copySummaryBtn,
.is-capturing #settings .header-actions {
  display: none !important;
}

.capture-preview {
  position: fixed;
  right: 18px;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 18px);
  z-index: 60;
  width: min(420px, calc(100vw - 32px));
  max-height: min(620px, calc(100vh - 32px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

.capture-preview-head,
.capture-preview-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
}

.capture-preview-head {
  background: var(--bear);
  color: #fff;
}

.capture-preview-head button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  cursor: pointer;
}

.capture-preview-note {
  padding: 10px 14px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  border-bottom: 0.5px solid var(--line);
}

.capture-preview img {
  width: 100%;
  min-height: 0;
  object-fit: contain;
  background: var(--bg);
}

.capture-preview-actions {
  border-top: 0.5px solid var(--line);
}

.capture-preview-actions a {
  color: var(--bear-deep);
  font-weight: 700;
  text-decoration: none;
}

/* ---------- Mobile: data tables -> stacked cards (iOS grouped form) ---------- */

@media (max-width: 599px) {
  .data-table {
    overflow: visible;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
  }

  .data-table table {
    width: 100%;
    min-width: 0;
    border-collapse: separate;
  }

  .data-table thead {
    display: none;
  }

  .data-table tbody {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .data-table tr {
    display: block;
    padding: 4px 16px;
    background: var(--surface);
    border-radius: var(--r-card);
    box-shadow: var(--shadow);
  }

  .data-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 0;
    border-bottom: 0.5px solid var(--line);
    text-align: right;
    font-size: 15px;
  }

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

  .data-table td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    white-space: nowrap;
  }

  .data-table td.output {
    font-weight: 700;
    color: var(--bear-deep);
  }

  .data-table td input,
  .data-table td select {
    width: auto;
    max-width: 62%;
    min-width: 0;
    padding: 4px 0;
    border: 0;
    background: transparent;
    text-align: right;
    font-weight: 600;
    -webkit-appearance: none;
    appearance: none;
  }

  .data-table td select {
    padding-right: 16px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238c8576' d='M6 8.5 2.5 5h7z'/%3E%3C/svg%3E") no-repeat right center;
  }

  .data-table td input:focus,
  .data-table td select:focus {
    outline: none;
    color: var(--bear-deep);
  }
}

/* ---------- Brand avatar ---------- */

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.brand-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  display: inline-block;
  flex: 0 0 auto;
}

.brand-avatar--fallback {
  display: grid;
  place-items: center;
  background: var(--bear);
  color: #fff;
  font-family: var(--font-round);
  font-weight: 800;
  font-size: 14px;
}

/* ---------- Hero + progress metric ---------- */

.metric--hero {
  grid-column: 1 / -1;
  background: linear-gradient(155deg, var(--bear) 0%, var(--bear-deep) 100%);
  color: #fff;
}

.metric--hero-high {
  background: linear-gradient(155deg, #c4673f 0%, #97401f 100%);
}

.metric--hero label {
  color: rgba(255, 255, 255, 0.9);
}

.metric--hero strong {
  font-size: 36px;
}

.metric--hero span {
  color: rgba(255, 255, 255, 0.82);
}

.metric--risk {
  background: linear-gradient(155deg, var(--bear) 0%, var(--bear-deep) 100%);
  color: #fff;
}

.metric--risk-high {
  background: linear-gradient(155deg, #c4673f 0%, #97401f 100%);
}

.metric--risk label {
  color: rgba(255, 255, 255, 0.9);
}

.metric--risk strong {
  font-size: 27px;
}

.metric--risk span {
  color: rgba(255, 255, 255, 0.85);
}

.metric--progress {
  grid-column: 1 / -1;
  background: var(--surface);
  color: var(--ink);
  display: block;
}

.progress-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.progress-pct {
  font-family: var(--font-round);
  font-weight: 800;
  font-size: 20px;
  color: var(--bear);
  font-variant-numeric: tabular-nums;
}

.progress-track {
  margin: 12px 0 10px;
  height: 12px;
  border-radius: 999px;
  background: var(--bear-soft);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--bear), var(--bear-deep));
  transition: width 0.5s ease;
}

.progress-meta {
  font-size: 13px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.progress-split {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.band-note {
  margin: -4px 4px 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

/* ---------- 分月中高风险收益 list ---------- */

.rr-empty {
  padding: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  background: var(--surface);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
}

.rr-list {
  background: var(--surface);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.rr-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  border-bottom: 0.5px solid var(--line);
}

.rr-item:last-child {
  border-bottom: 0;
}

.rr-month {
  min-width: 62px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.rr-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
}

.rr-dot--on {
  background: var(--pos);
}

.rr-amt {
  flex: 1 1 auto;
  text-align: right;
  font-weight: 700;
  color: var(--bear-deep);
  font-variant-numeric: tabular-nums;
}

.rr-amt--neg {
  color: var(--neg);
}

/* 收益/损失 符号切换按钮 */
.rr-sign {
  flex: 0 0 auto;
  width: 34px;
  height: 36px;
  border: 0.5px solid var(--hairline);
  border-radius: 8px;
  background: var(--surface);
  color: var(--pos);
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.rr-sign--neg {
  color: var(--neg);
}
.rr-sign:active {
  transform: scale(0.92);
}

/* 删除按钮 */
.rr-del {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 16px;
  cursor: pointer;
}
.rr-del:active {
  transform: scale(0.92);
}

.rr-src {
  flex: 0 0 auto;
  max-width: 84px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
}

.rr-tag {
  margin-left: auto;
  font-size: 11px;
  color: var(--faint);
  white-space: nowrap;
}

.rr-tag--on {
  color: var(--pos);
}

.rr-edit-btn {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.rr-edit-btn:active {
  background: var(--bear-soft);
  transform: scale(0.92);
}

.rr-item--edit {
  flex-wrap: wrap;
  background: var(--surface-2);
}

.rr-in {
  border: 0.5px solid var(--hairline);
  border-radius: 8px;
  padding: 9px 10px;
  background: var(--surface);
  font: inherit;
  -webkit-appearance: none;
  appearance: none;
}

.rr-in--month {
  width: 96px;
}

.rr-in--amt {
  width: 96px;
}

.rr-in--src {
  flex: 1 1 120px;
}

.rr-done {
  margin-left: auto;
  height: 36px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--bear);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- metric card mini detail list (可投资 / 未来奖金) ---------- */

.metric--list {
  display: block;
  grid-column: 1 / -1;
}

.fi-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.fi-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 11.5px;
  line-height: 1.3;
  color: var(--muted);
}

.fi-ym {
  flex: 0 0 auto;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.fi-label {
  flex: 1 1 auto;
  min-width: 0;
}

.fi-amt {
  flex: 0 0 auto;
  margin-left: auto;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- risk breakdown sub-tables ---------- */

.rb-sub {
  display: flex;
  align-items: center;
  margin: 4px 0 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.rb-zoom {
  margin-left: auto;
  font-size: 15px;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  opacity: 0.75;
}
.rb-zoom:active {
  opacity: 1;
  transform: scale(0.92);
}

/* 弹窗内：货币切换段控件 + 汇总 + 详析 */
.seg {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 12px;
  margin-bottom: 14px;
}
.seg-btn {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 0;
  border-radius: 9px;
  cursor: pointer;
}
.seg-btn.on {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
.rg-summary {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: 14px;
  margin-bottom: 16px;
}
.rg-stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.rg-stat span {
  color: var(--muted);
  font-size: 13px;
}
.rg-stat b {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}
.rg-stat--total {
  margin-top: 4px;
  padding-top: 10px;
  border-top: 0.5px solid var(--hairline);
}
.rg-stat--total span {
  color: var(--ink);
  font-weight: 600;
}
.rg-stat--total b {
  font-size: 19px;
  font-weight: 800;
  color: var(--bear-deep);
}
.rg-note {
  margin-top: 14px;
}
.rg-pos {
  color: var(--pos);
}
.rg-neg {
  color: var(--neg);
}
.rg-detail-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 2px;
}
.fi-risk {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--bear-soft);
  color: var(--bear-deep);
  font-size: 10px;
}
.fi-tag {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--line);
  color: var(--muted);
  font-size: 10px;
}
.fi-cost {
  margin-left: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

.rb-sub + table {
  margin-bottom: 14px;
}

.rb-empty {
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 14px;
}

/* 预测图柱子点击后的明细横条 */
.forecast-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  padding: 10px 14px;
  background: var(--surface-2);
  border-radius: 12px;
  font-size: 12.5px;
  color: var(--ink);
  white-space: nowrap;
  overflow-x: auto;
}

#forecastTable {
  touch-action: pan-x;
  -webkit-overflow-scrolling: touch;
}

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

/* AI 摘要卡片 */
.ai-card {
  background: var(--surface);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  padding: 18px;
}

.ai-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.ai-emoji {
  font-size: 30px;
}

.ai-emoji-img {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  object-fit: cover;
  flex: none;
}

.ai-title {
  font-family: var(--font-round);
  font-size: 18px;
  font-weight: 800;
}

.ai-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

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

.ai-kv {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 10px 12px;
}

.ai-kv span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}

.ai-kv b {
  font-family: var(--font-round);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.ai-section {
  margin-top: 14px;
}

.ai-st {
  font-size: 13px;
  font-weight: 700;
  color: var(--bear-deep);
  margin-bottom: 4px;
}

.ai-section p {
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink);
}

/* 季度对比 */
.cmp-pick {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.cmp-pick label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.cmp-pick select {
  border: 0.5px solid var(--hairline);
  border-radius: 8px;
  padding: 7px 10px;
  background: var(--surface);
  font: inherit;
}

.cmp-up {
  color: var(--pos);
}

.cmp-down {
  color: var(--neg);
}

.cmp-analysis {
  margin-top: 16px;
  background: var(--surface);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  padding: 16px;
}

.cmp-analysis h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 8px;
}

.cmp-analysis p {
  font-size: 13px;
  line-height: 1.65;
  color: var(--ink);
}

/* ---------- 新手欢迎页 ---------- */

.welcome[hidden] {
  display: none !important;
}

.welcome {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 24px) 28px calc(var(--safe-bottom) + 24px);
  background: linear-gradient(160deg, #fbf3e2 0%, #f1e2c4 100%);
}

@media (prefers-color-scheme: dark) {
  .welcome {
    background: linear-gradient(160deg, #221c15 0%, #16130e 100%);
  }
}

.welcome-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.welcome-icon {
  width: 104px;
  height: 104px;
  border-radius: 26px;
  object-fit: cover;
  box-shadow: 0 12px 34px rgba(224, 145, 27, 0.32);
  margin-bottom: 22px;
}

.welcome-title {
  font-family: var(--font-round);
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.welcome-sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.welcome-btn {
  margin-top: 34px;
  width: 100%;
  height: 50px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(155deg, var(--bear) 0%, var(--bear-deep) 100%);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.welcome-btn:active {
  transform: scale(0.98);
}

.welcome-link {
  margin-top: 14px;
  border: 0;
  background: transparent;
  color: var(--bear-deep);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.welcome-note {
  margin-top: 26px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

/* ===== 显示设置弹窗 ===== */
.theme-opts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 4px 0 18px;
}
.theme-opt {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 12px 12px;
  border: 2px solid var(--hairline);
  border-radius: var(--r-card);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.theme-opt:active {
  transform: scale(0.98);
}
.theme-opt.is-active {
  border-color: var(--bear);
}
.theme-opt-label {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}
.theme-opt-check {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--bear);
  color: #fff;
  font-size: 13px;
  line-height: 20px;
  text-align: center;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.theme-opt.is-active .theme-opt-check {
  opacity: 1;
  transform: scale(1);
}

/* 迷你首页缩略图 */
.theme-thumb {
  width: 100%;
  aspect-ratio: 16 / 11;
  border-radius: 12px;
  padding: 9px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(128, 128, 128, 0.12);
}
.theme-thumb--light {
  background: #f4f1ea;
}
.theme-thumb--dark {
  background: #16130e;
}
.theme-thumb .tt-top {
  display: flex;
  align-items: center;
  gap: 5px;
}
.theme-thumb .tt-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #e0911b;
  flex: none;
}
.theme-thumb .tt-line {
  height: 6px;
  width: 46%;
  border-radius: 999px;
}
.theme-thumb .tt-card {
  flex: 1;
  border-radius: 8px;
}
.theme-thumb .tt-row {
  display: flex;
  gap: 6px;
}
.theme-thumb .tt-pill {
  flex: 1;
  height: 12px;
  border-radius: 6px;
}
.theme-thumb--light .tt-line {
  background: rgba(40, 32, 16, 0.18);
}
.theme-thumb--light .tt-card {
  background: #fff;
  box-shadow: 0 1px 3px rgba(30, 24, 10, 0.08);
}
.theme-thumb--light .tt-pill {
  background: #fff;
}
.theme-thumb--dark .tt-line {
  background: rgba(255, 255, 255, 0.2);
}
.theme-thumb--dark .tt-card {
  background: #211c15;
}
.theme-thumb--dark .tt-pill {
  background: #2a241b;
}

/* 跟随系统 行 + 开关 */
.theme-auto {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-radius: var(--r-card);
  background: var(--surface-2);
  cursor: pointer;
}
.theme-auto-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.theme-auto-text b {
  font-size: 15px;
  color: var(--ink);
}
.theme-auto-text small {
  font-size: 12px;
  color: var(--muted);
}
.switch {
  flex: none;
  width: 50px;
  height: 30px;
  border-radius: 999px;
  background: var(--hairline);
  position: relative;
  transition: background 0.2s ease;
}
.switch.on {
  background: var(--pos);
}
.switch-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease;
}
.switch.on .switch-knob {
  transform: translateX(20px);
}

/* 风险拆解表（规范）：表头与数据都居中对齐、避免列被压到竖排折叠 */
#riskAssetTable th,
#riskAssetTable td,
#riskDenominatorTable th,
#riskDenominatorTable td {
  text-align: center;
  white-space: nowrap;
}

#riskAssetTable th:first-child,
#riskAssetTable td:first-child,
#riskDenominatorTable th:first-child,
#riskDenominatorTable td:first-child {
  white-space: normal;
}

/* 分母口径表的「说明」列是长文本：表头居中、数据左对齐并允许换行 */
#riskDenominatorTable th:last-child {
  white-space: normal;
}
#riskDenominatorTable td:last-child {
  text-align: left;
  white-space: normal;
}

/* ---------- Tappable metric cards + center modal ---------- */

.metric--tappable {
  position: relative;
  cursor: pointer;
}

.metric--tappable:active {
  transform: scale(0.985);
}

.metric-zoom {
  position: absolute;
  bottom: 14px;
  right: 14px;
  font-size: 15px;
  opacity: 0.7;
}

.metric-cur {
  display: block;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.24s;
}

.modal-backdrop.open {
  opacity: 1;
}

.modal-sheet {
  position: fixed;
  z-index: 61;
  left: 50%;
  top: 50%;
  width: min(440px, calc(100vw - 36px));
  max-height: 72vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px;
  background: var(--surface);
  border-radius: 22px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.32);
  transform: translate(-50%, -48%) scale(0.96);
  opacity: 0;
  transition: opacity 0.22s, transform 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}

.modal-sheet.open {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.modal-title {
  font-family: var(--font-round);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 2px 0 14px;
  padding-right: 34px;
}

.modal-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin: 0 0 12px;
}

.modal-sub {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin: 14px 0 6px;
}

.modal-sub:first-child {
  margin-top: 0;
}

.modal-body .fi-row {
  font-size: 13.5px;
  padding: 4px 0;
  border-bottom: 0.5px solid var(--line);
}

.modal-body .fi-row:last-child {
  border-bottom: 0;
}
