/* ============ 《我的指数日志》全局样式 ============ */
:root {
  --primary: #2b6cb0;
  --primary-dark: #1e4e80;
  --bg: #f5f7fa;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1a202c;
  --text-2: #4a5568;
  --text-3: #a0aec0;
  /* 中国习惯：涨/正收益 = 红，跌/负收益 = 绿 */
  --up: #e03131;
  --down: #0ca678;
  --buy: #2b6cb0;   /* 买入点 = 蓝 */
  --sell: #e03131;  /* 卖出点 = 红 */
  --shadow: 0 2px 12px rgba(0,0,0,.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
  overscroll-behavior: none;
}

/* ============ 视图切换 ============ */
.view { display: none; height: 100%; flex-direction: column; overflow: hidden; }
.view.active { display: flex; }
.view.fullscreen { position: fixed; inset: 0; z-index: 50; background: var(--bg); }

/* ============ 首页 ============ */
.home-header { padding: 48px 24px 24px; text-align: center; }
.home-header h1 { font-size: 26px; letter-spacing: 2px; color: var(--primary-dark); }
.home-sub { margin-top: 8px; font-size: 13px; color: var(--text-3); }
.entries { padding: 8px 20px; display: flex; flex-direction: column; gap: 14px; }
.entry {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  padding: 20px; border: none; border-radius: 16px; background: var(--card);
  box-shadow: var(--shadow); cursor: pointer; text-align: left;
  border-left: 5px solid var(--primary); transition: transform .12s;
}
.entry:active { transform: scale(.97); }
.entry-icon { font-size: 24px; color: var(--primary); }
.entry-name { font-size: 18px; font-weight: 700; }
.entry-desc { font-size: 12px; color: var(--text-3); }
.entry-long { border-left-color: var(--up); } .entry-long .entry-icon { color: var(--up); }
.entry-stats { border-left-color: var(--down); } .entry-stats .entry-icon { color: var(--down); }
.home-footer { padding: 20px; text-align: center; }
.ghost-btn { background: none; border: 1px solid var(--border); color: var(--text-2);
  padding: 8px 18px; border-radius: 20px; font-size: 13px; cursor: pointer; }

/* ============ 顶栏 ============ */
.topbar {
  display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 12px;
  background: var(--card); border-bottom: 1px solid var(--border); flex-shrink: 0;
  position: relative; z-index: 5;
}
.topbar-back { background: none; border: none; font-size: 22px; color: var(--primary);
  cursor: pointer; padding: 4px 8px; }
.topbar-title { flex: 1; text-align: center; font-size: 16px; font-weight: 600; overflow: hidden; }
.topbar-help { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--bg); color: var(--text-2); cursor: pointer; font-size: 15px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-action { background: var(--primary); border: none; color: #fff; font-size: 13px;
  padding: 6px 12px; border-radius: 6px; cursor: pointer; }
.topbar-action:disabled { background: var(--border); color: var(--text-3); cursor: not-allowed; }

/* ============ 主体容器 ============ */
.grid-main, .long-main, .stats-main { flex: 1; overflow-y: auto; padding: 12px; -webkit-overflow-scrolling: touch; }

/* ============ 坐标系卡片（有边框、相对独立） ============ */
.chart-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px; box-shadow: var(--shadow); position: relative;
}
.chart-head { display: flex; align-items: center; justify-content: center; position: relative; padding: 4px 0 8px; }
.chart-head-text { text-align: center; flex: 1; }
.chart-head-name { font-size: 15px; font-weight: 700; }
.chart-head-code { font-size: 11px; color: var(--text-3); }
.chart-nav { background: none; border: none; font-size: 20px; color: var(--primary);
  cursor: pointer; padding: 0 10px; }
.chart-settings { position: absolute; right: 6px; top: 6px; background: none; border: none;
  font-size: 18px; cursor: pointer; color: var(--text-2); }
.chart-svg-wrap { width: 100%; touch-action: none; }
.chart-svg-wrap svg { width: 100%; height: auto; display: block; }

/* 坐标系右下角浮动按钮（全屏内仍绝对定位） */
.chart-fabs { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 8px; z-index: 3; }
.chart-fab { width: 40px; height: 40px; border-radius: 50%; border: none; background: var(--card);
  box-shadow: var(--shadow); cursor: pointer; font-size: 16px; color: var(--primary); }

/* 小窗口：按钮在图表下方正常流 */
.chart-fabs-below { position: static; flex-direction: row; justify-content: center; gap: 12px; margin-top: 12px; }
.chart-fabs-below .chart-fab { box-shadow: none; border: 1px solid var(--border); }

/* ============ 入口按钮（记录交易） ============ */
.big-entry { display: block; width: 100%; margin-top: 12px; padding: 14px; border: none;
  border-radius: 12px; background: var(--primary); color: #fff; font-size: 16px;
  font-weight: 600; cursor: pointer; box-shadow: var(--shadow); }
.big-entry:active { background: var(--primary-dark); }

/* ============ 记录表格（全屏可缩放） ============ */
.record-body { flex: 1; overflow: hidden; position: relative; }
.record-scroll { height: 100%; overflow: auto; touch-action: pan-x pan-y; }
.record-table { border-collapse: collapse; background: var(--card); font-size: 13px; }
.record-table th, .record-table td { border: 1px solid var(--border); padding: 8px 10px;
  min-width: 84px; text-align: center; white-space: nowrap; }
.record-table th { background: #f0f4f8; font-weight: 600; position: sticky; }
.record-table td[contenteditable="true"] { background: #fffbea; outline: 2px solid var(--primary); }
.record-table .fixed-col { position: sticky; left: 0; background: #f0f4f8; z-index: 2; }

/* 表格右下角统计浮窗 */
.record-stats { position: absolute; right: 10px; bottom: 10px; background: var(--card);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  padding: 8px 12px; font-size: 12px; z-index: 3; }
.record-stats div { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
.record-stats .label { color: var(--text-2); }
.record-stats .val { font-weight: 600; font-variant-numeric: tabular-nums; }
.val.pos { color: var(--up); } .val.neg { color: var(--down); }

/* ============ 弹层 ============ */
.modal-mask { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 100; align-items: center; justify-content: center; padding: 20px; }
.modal-mask.open { display: flex; }
.modal-box { background: var(--card); border-radius: 14px; width: 100%; max-width: 400px;
  max-height: 84%; overflow-y: auto; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 600; position: sticky; top: 0; background: var(--card); }
.modal-close { background: none; border: none; font-size: 18px; color: var(--text-3); cursor: pointer; }
.modal-body { padding: 16px; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.form-row input, .form-row select { width: 100%; padding: 10px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 15px; }
.modal-foot { display: flex; gap: 10px; padding: 0 16px 16px; }
.modal-foot button { flex: 1; padding: 11px; border-radius: 8px; border: none; font-size: 15px; cursor: pointer; }
.btn-confirm { background: var(--primary); color: #fff; }
.btn-cancel { background: var(--bg); color: var(--text-2); border: 1px solid var(--border); }

/* 公式说明 */
.formula-content { padding: 16px; font-size: 13px; line-height: 1.8; color: var(--text-2); }
.formula-content h4 { color: var(--text); margin: 10px 0 4px; }
.formula-content code { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 12px; }

/* ============ 统计 ============ */
.stats-section { background: var(--card); border-radius: 12px; padding: 14px; margin-bottom: 14px; box-shadow: var(--shadow); }
.stats-section h3 { font-size: 15px; margin-bottom: 10px; color: var(--primary-dark); }
.stats-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.stats-row:last-child { border-bottom: none; }
.fund-item { display: flex; justify-content: space-between; align-items: center; padding: 12px;
  background: var(--card); border-radius: 10px; margin-bottom: 8px; box-shadow: var(--shadow); cursor: pointer; }

.chart-full-body, .detail-body { flex: 1; overflow: hidden; position: relative; }

/* ============ 拖动排序 ============ */
.record-scroll { position: relative; user-select: none; -webkit-user-select: none; }
.record-scroll.dragging { touch-action: none; }
.dragging-col { opacity: 0.35; }
.drag-ghost {
  position: fixed; pointer-events: none; z-index: 1000;
  background: rgba(255, 255, 255, 0.95); border: 2px solid var(--primary);
  border-radius: 8px; box-shadow: var(--shadow); padding: 6px 8px;
  font-size: 13px; color: var(--text); white-space: nowrap;
}
.drag-gap {
  position: absolute; top: 0; bottom: 0; width: 4px;
  background: var(--primary); opacity: 0; pointer-events: none; z-index: 10;
  transition: opacity 0.1s;
}
.drag-gap.active { opacity: 0.8; }
.drag-target td { background: #e6fffa !important; }
