/* ========== 基金收益计算系统 - 响应式样式（移动优先，PC ≥768px 自适应） ========== */
:root {
  --bg: #f1f4f9;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #8a94a6;
  --line: #e4e9f1;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --up: #e5484d;      /* 盈/涨（中国习惯：红） */
  --down: #0e9f6e;    /* 亏/跌（绿） */
  --topbar-bg: #1e293b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(30, 41, 59, .08), 0 4px 14px rgba(30, 41, 59, .06);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}
.hidden { display: none !important; }
h2 { font-size: 15px; margin-bottom: 10px; color: #334155; }
a { color: var(--primary); }

/* ---------- 通用控件 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 40px; padding: 0 16px;
  border: 1px solid #cbd5e1; border-radius: 8px;
  background: #fff; color: var(--text);
  font-size: 14px; cursor: pointer; user-select: none;
  transition: background .15s, border-color .15s;
}
.btn:active { background: #eef2f7; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:active { background: var(--primary-dark); }
.btn.danger { background: #fff; border-color: #f0b4b6; color: var(--up); }
.btn.ghost { background: transparent; border-color: transparent; color: #cbd5e1; }
.btn.ghost:hover { color: #fff; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select {
  width: 100%; min-height: 42px; padding: 8px 10px;
  border: 1px solid #cbd5e1; border-radius: 8px;
  background: #fff; color: var(--text); font-size: 15px;
}
input:focus, select:focus { outline: 2px solid rgba(37, 99, 235, .35); border-color: var(--primary); }
select { appearance: auto; }

.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px;
}
.alert { padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.alert-warn { background: #fff7e6; color: #ad6800; border: 1px solid #ffd591; }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; background: rgba(255,255,255,.15); color: #e2e8f0;
}
.form-hint { font-size: 12px; color: var(--muted); margin-top: 8px; }
.about { font-size: 13px; color: var(--muted); line-height: 1.8; }

/* ---------- 登录 ---------- */
.auth-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: linear-gradient(160deg, #1e293b 0%, #334155 100%);
}
.auth-card {
  width: 100%; max-width: 380px; background: #fff;
  border-radius: 16px; padding: 28px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.auth-logo { font-size: 40px; text-align: center; }
.auth-card h1 { font-size: 19px; text-align: center; margin: 10px 0 6px; }
.auth-hint { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.auth-card input { margin-bottom: 10px; }
.auth-msg { min-height: 20px; font-size: 13px; color: var(--up); margin-top: 10px; text-align: center; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  background: var(--topbar-bg); color: #fff;
  padding: 10px 14px; box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.brand { font-weight: 600; font-size: 16px; margin-right: auto; }
#fetch-badge { flex: none; }

/* ---------- Tab 导航：移动端底部固定 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 10px rgba(30,41,59,.08);
}
.tab-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 56px; padding: 7px 2px 5px;
  border: none; background: none; color: var(--muted);
  font-size: 11px; cursor: pointer;
}
.tab-icon { font-size: 20px; line-height: 1; }
.tab-btn.active { color: var(--primary); font-weight: 600; }

/* ---------- 内容区 ---------- */
.content { padding: 12px 12px calc(76px + env(safe-area-inset-bottom)); max-width: 1200px; margin: 0 auto; }

/* ---------- 指标卡片 ---------- */
.metric-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.metric {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px;
}
.metric .m-label { font-size: 12px; color: var(--muted); }
.metric .m-value { font-size: 20px; font-weight: 700; margin-top: 2px; word-break: break-all; }
.m-value.sm { font-size: 16px; }
.metric .m-value.sm { font-size: 16px; }
.metric .m-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.metric .m-value.sm { font-size: 16px; }
.up { color: var(--up); }
.down { color: var(--down); }

/* ---------- 分类徽章 ---------- */
.cat-badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; color: #fff; white-space: nowrap;
}
.cat-纯债 { background: #0e9f6e; }
.cat-混合 { background: #7c3aed; }
.cat-ETF  { background: #2563eb; }
.cat-QDII { background: #0891b2; }
.cat-红利 { background: #d97706; }
.cat-黄金 { background: #ca8a04; }
.cat-其他 { background: #64748b; }

/* ---------- 行列表（持仓/交易）移动端卡片化 ---------- */
.row-list { display: flex; flex-direction: column; gap: 8px; }
.row-item {
  background: #f8fafc; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; display: grid; gap: 4px 10px;
  grid-template-columns: 1fr auto;
}
.row-item .r-main { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-item .r-title { font-weight: 600; font-size: 14px; }
.row-item .r-sub { font-size: 12px; color: var(--muted); }
.row-item .r-right { text-align: right; }
.row-item .r-actions { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: flex-end; }
.row-item .r-actions .btn { min-height: 32px; padding: 0 10px; font-size: 12px; }
.empty-tip { text-align: center; color: var(--muted); padding: 28px 0; font-size: 13px; }

/* ---------- 交易表单 ---------- */
.tx-form { display: grid; grid-template-columns: 1fr; gap: 10px; }
.tx-form .field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.form-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.form-hint { flex: 1; min-width: 120px; }

/* 类型徽章 */
.t-buy, .t-sell, .t-div_cash, .t-div_reinvest {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; color: #fff;
}
.t-buy { background: var(--up); }
.t-sell { background: var(--down); }
.t-div_cash { background: #d97706; }
.t-div_reinvest { background: #7c3aed; }

/* ---------- 图表 ---------- */
.chart { width: 100%; height: 300px; }
.chart-sm { width: 100%; height: 210px; }
.chart-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }

/* ---------- 设置 ---------- */
.inline-form { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 140px; }
.inline-form select { flex: 1; min-width: 120px; }
.inline-form .btn { flex: none; }
.search-results { max-height: 240px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 10px; }
.search-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-bottom: 1px solid var(--line); font-size: 13px;
}
.search-item:last-child { border-bottom: none; }
.search-item .s-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-item .s-code { color: var(--muted); font-size: 12px; }

.fund-list-item {
  display: grid; gap: 6px 10px; grid-template-columns: 1fr;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px;
  background: #f8fafc;
}
.fund-list-item .fl-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fund-list-item .fl-head .fl-name { font-weight: 600; font-size: 14px; flex: 1; min-width: 120px; }
.fund-list-item .fl-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fund-list-item .fl-fields label { font-size: 11px; color: var(--muted); display: block; margin-bottom: 2px; }
.fund-list-item .fl-fields input, .fund-list-item .fl-fields select { min-height: 34px; font-size: 13px; }

.fetch-status { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.fetch-log {
  background: #0f172a; color: #a5f3fc; font-size: 11px;
  border-radius: 8px; padding: 10px; margin-top: 10px;
  max-height: 260px; overflow-y: auto; white-space: pre-wrap; word-break: break-all;
  font-family: ui-monospace, Consolas, "Courier New", monospace;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  background: rgba(15, 23, 42, .92); color: #fff; font-size: 13px;
  padding: 9px 16px; border-radius: 999px; z-index: 99;
  max-width: 90vw; box-shadow: 0 6px 20px rgba(0,0,0,.3);
}

/* ================================================================
   PC 断点（≥768px）
   ================================================================ */
@media (min-width: 768px) {
  body { font-size: 14px; }
  .content { padding: 16px 20px 40px; }

  /* 导航移到顶部 */
  .tabbar {
    position: static;
    display: flex; justify-content: center; gap: 4px;
    background: var(--topbar-bg); border-top: none;
    padding: 0 20px calc(0px);
    box-shadow: none;
  }
  .tab-btn {
    flex-direction: row; gap: 6px; min-height: 44px; padding: 0 18px;
    font-size: 14px; color: #cbd5e1; border-bottom: 2px solid transparent;
  }
  .tab-btn.active { color: #fff; border-bottom-color: #60a5fa; }
  .tab-icon { font-size: 16px; }

  /* 指标仪表盘 */
  .metric-grid { grid-template-columns: repeat(4, 1fr); gap: 12px; }
  .metric .m-value { font-size: 24px; }
  .card { padding: 18px 20px; }

  /* 持仓表：行变宽列（7 列：名称 | 盈亏 | 市值 | 份额 | 净值 | 年化/已实现 | 操作） */
  .row-item {
    grid-template-columns: 1.6fr 1fr 1fr 1fr 1.4fr 1fr auto;
    align-items: center; padding: 8px 14px;
  }
  .row-item .r-actions { grid-column: auto; }
  .row-item .r-right { text-align: right; }

  /* 交易表单两列 */
  .tx-form { grid-template-columns: 1fr 1fr; }
  .tx-form .span2 { grid-column: 1 / -1; }

  /* 图表双列 */
  .chart-grid { grid-template-columns: 1fr 1fr; }
  .chart-grid .wide { grid-column: 1 / -1; }
  .chart { height: 360px; }

  /* 设置：基金列表两列 */
  .fund-list-item { grid-template-columns: 1fr 2fr; align-items: center; }
  .fund-list { display: grid; grid-template-columns: 1fr; gap: 8px; }
}

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