/* 自选股跟踪 —— 极简表格样式
 *
 * 布局要点（对应任务书 3.2 / 十二章）：
 *  · 整个表格放在一个双向滚动容器里，第一列与表头用 sticky 钉住
 *  · 红涨绿跌平灰（A 股习惯，与欧美相反）
 *  · 数字用 tabular-nums 等宽，纵向比较时位数对齐
 *  · 价格与涨跌幅分两行，字号递减，信息密度高但不挤
 */

:root {
  --ink: #1f2329;
  --sub: #6b7280;
  --line: #e8eaed;
  --line-strong: #d5d8dd;
  --bg: #ffffff;
  --bg-soft: #fafbfc;
  --up: #d93025;      /* 涨：红 */
  --down: #12805c;    /* 跌：绿 */
  --flat: #8b9099;    /* 平：灰 */
  --blue: #2563eb;
  --col-stock: 92px;
  --col-date: 78px;
  --row-h: 52px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;   /* 移动端地址栏收放时更准 */
}

/* ── 顶部栏 ─────────────────────────────────────────── */
.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.bar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.actions {
  display: flex;
  gap: 6px;
}

/* 图标用内联 SVG，不依赖系统字体里有没有 ＋ / ✎ 这些字符。
   之前用全角字符做图标，在无头浏览器/部分安卓机型上直接渲染成空白。 */
.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: #f4f5f7;
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
}

.icon-btn:hover { background: #e9ecf1; }
.icon-btn:active { background: var(--line-strong); }
.icon-btn.active { background: #e0e9ff; color: var(--blue); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }

/* ── 状态行 ─────────────────────────────────────────── */
.status {
  flex: 0 0 auto;
  padding: 6px 14px 7px;
  font-size: 11.5px;
  color: var(--sub);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--flat);
  flex: 0 0 auto;
}

.status .dot.live { background: var(--up); animation: pulse 2s ease-in-out infinite; }
.status .dot.warn { background: #e0a800; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ── 表格滚动容器 ───────────────────────────────────── */
.wrap {
  flex: 1 1 auto;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  position: relative;
  background: var(--bg);
}

table {
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* 表头固定 */
thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line-strong);
  font-weight: 500;
  font-size: 12px;
  color: var(--sub);
  padding: 8px 6px;
  text-align: right;
  white-space: nowrap;
  height: 32px;
}

/* 第一列固定 */
th.stock-col,
td.stock-col {
  position: sticky;
  left: 0;
  width: var(--col-stock);
  min-width: var(--col-stock);
  max-width: var(--col-stock);
  text-align: left;
  padding-left: 14px;
  padding-right: 8px;
  background: var(--bg);
  border-right: 1px solid var(--line-strong);
}

thead th.stock-col {
  z-index: 5;              /* 左上角压住所有 */
  background: var(--bg-soft);
}

tbody td:not(.stock-col) {
  background: var(--bg);
}

tbody td.stock-col { z-index: 2; }

tbody td {
  border-bottom: 1px solid var(--line);
  padding: 6px 6px;
  height: var(--row-h);
  vertical-align: middle;
  text-align: right;
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: 1px solid var(--line-strong); }

/* ── 股票名单元格 ───────────────────────────────────── */
.stock-link {
  display: block;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.stock-link:hover { color: var(--blue); }
.stock-link:active { opacity: 0.6; }

.stock-sub {
  font-size: 10.5px;
  color: var(--sub);
  font-variant-numeric: tabular-nums;
  margin-top: 1px;
}

/* ── 价格单元格：两行 ───────────────────────────────── */
.cell {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  line-height: 1.25;
}

.cell .price {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
}

.cell .pct {
  font-size: 11px;
  color: var(--flat);
}

.cell.up .price { color: var(--up); }
.cell.up .pct { color: var(--up); }
.cell.down .price { color: var(--down); }
.cell.down .pct { color: var(--down); }
.cell.flat .price { color: var(--ink); }
.cell.flat .pct { color: var(--flat); }

/* 盘中未收盘的格子加一个极轻的角标，避免被误当收盘价 */
.cell.live .pct::after {
  content: "";
  display: inline-block;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
  margin-left: 3px;
  vertical-align: middle;
}

.cell .empty {
  color: #c8ccd2;
  font-size: 12px;
}

/* ── 空状态 ─────────────────────────────────────────── */
.empty-state {
  padding: 64px 24px;
  text-align: center;
  color: var(--sub);
  font-size: 13.5px;
  line-height: 1.9;
}

.empty-state .big {
  font-size: 26px;
  margin-bottom: 10px;
  opacity: 0.3;
}

/* ── 加载更多（横向 seam 提示）──────────────────────── */
.more-hint {
  position: sticky;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  font-size: 11.5px;
  color: var(--sub);
}

.seam {
  display: inline-block;
  width: 100%;
  text-align: center;
  font-size: 11.5px;
  color: var(--sub);
  padding: 8px;
}

/* 左缘提示：日期是正序排列（左边更早、右边最新），首屏停在最右端，
   所以"还能往左滑看更早"的提示落在第一列右边缘——给 sticky 首列一条极轻投影。
   不能用 .wrap 的内阴影：首列是 sticky left:0 且 z-index 更高，会把左侧那条阴影整条盖住。 */
.wrap.can-left th.stock-col,
.wrap.can-left td.stock-col {
  box-shadow: 8px 0 10px -8px rgba(15, 23, 42, 0.22);
}

/* ── 弹窗 ───────────────────────────────────────────── */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.32);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  animation: fade 0.14s ease;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: min(420px, 100%);
  max-height: 86vh;
  overflow: auto;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
  padding: 20px;
  animation: rise 0.16s ease;
}

@keyframes rise {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal h2 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 600;
}

.modal p.hint {
  margin: 0 0 16px;
  font-size: 12.5px;
  color: var(--sub);
  line-height: 1.6;
}

.modal input[type="password"],
.modal input[type="text"],
.modal textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  outline: none;
  color: var(--ink);
  background: #fff;
}

.modal textarea { resize: vertical; min-height: 64px; line-height: 1.6; }

.modal input:focus,
.modal textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.modal .row {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.btn {
  flex: 1;
  padding: 10px;
  font-size: 14.5px;
  font-family: inherit;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:disabled { background: #9aa4b2; cursor: not-allowed; }
.btn.ghost { background: #f2f4f7; color: var(--ink); }
.btn.ghost:hover { background: #e9ecf1; }

.err {
  margin: 12px 0 0;
  padding: 9px 11px;
  border-radius: 8px;
  background: #fef2f2;
  color: var(--up);
  font-size: 12.5px;
  line-height: 1.6;
}

/* ── 候选列表 ───────────────────────────────────────── */
.candidates {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  max-height: 300px;
  overflow-y: auto;
}

.cand-group + .cand-group { border-top: 1px solid var(--line); }

.cand-term {
  padding: 7px 12px;
  font-size: 11.5px;
  color: var(--sub);
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
}

.cand-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
  -webkit-tap-highlight-color: transparent;
}

.cand-item:last-child { border-bottom: 0; }
.cand-item:hover { background: var(--bg-soft); }
.cand-item.picked { background: #eef4ff; }

.cand-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--blue);
  flex: 0 0 auto;
}

.cand-name { font-size: 14px; font-weight: 500; }
.cand-code { font-size: 11.5px; color: var(--sub); font-variant-numeric: tabular-nums; }
.cand-tag {
  font-size: 10.5px;
  color: var(--sub);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 0 4px;
  margin-left: auto;
}

.cand-none {
  padding: 14px 12px;
  font-size: 12.5px;
  color: var(--sub);
}

.loading-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  font-size: 12.5px;
  color: var(--sub);
}

.spinner {
  width: 13px;
  height: 13px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ── 编辑模式 ───────────────────────────────────────── */
/* 编辑态首列要同时放"手柄 + 名称"和"代码 + 删除"，稍放宽一点，避免名称被截断 */
body.editing { --col-stock: 116px; }
body.editing td.stock-col { padding-left: 6px; padding-right: 4px; }

/* 编辑态的两行结构：不允许再被挤成四行 */
.stock-line {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.stock-line .stock-link { flex: 1 1 auto; min-width: 0; }

.stock-line.sub-line { margin-top: 1px; }
.stock-line .stock-sub { flex: 1 1 auto; min-width: 0; margin-top: 0; }

.drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 24px;
  height: 26px;
  margin-right: 0;
  color: #b6bcc6;
  cursor: grab;
  touch-action: none;      /* 拖动时禁止页面滚动 */
  font-size: 12px;
  user-select: none;
  -webkit-user-select: none;
}

.drag-handle:active { cursor: grabbing; }

.del-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  margin-left: auto;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #c0392b;
  font-size: 13px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.del-btn:hover { background: #fef2f2; }

tr.dragging {
  opacity: 0.55;
  background: #f5f8ff !important;
}

tr.dragging td { background: #f5f8ff !important; }

.edit-tip {
  flex: 0 0 auto;
  padding: 7px 14px;
  font-size: 11.5px;
  color: #8a5a00;
  background: #fffbeb;
  border-bottom: 1px solid #fde68a;
}

/* 授权剩余时间那行（只在编辑模式可见，给"24 小时授权"一个可见入口和撤销按钮） */
.edit-tip .auth-line {
  margin-top: 3px;
  color: #9a6b12;
  font-size: 11px;
}
.edit-tip .auth-line:empty { display: none; }

.link-btn {
  border: 0;
  background: none;
  padding: 0 0 0 4px;
  font: inherit;
  color: #b45309;
  text-decoration: underline;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ── 窄屏微调 ───────────────────────────────────────── */
@media (max-width: 400px) {
  :root {
    --col-stock: 84px;
    --col-date: 72px;
    --row-h: 49px;
  }
  .bar { padding: 10px 12px 9px; }
  .bar h1 { font-size: 16px; }
  .status { padding: 5px 12px 6px; font-size: 11px; }
  th.stock-col, td.stock-col { padding-left: 12px; padding-right: 6px; }
  .stock-link { font-size: 12.5px; }
  .cell .price { font-size: 12.5px; }
  .cell .pct { font-size: 10.5px; }
  tbody td { padding: 5px 4px; }
  thead th { padding: 7px 4px; font-size: 11.5px; }
}

@media (prefers-color-scheme: dark) {
  /* 任务书要求浅色底，这里只做最低限度的可读性适配，不改变整体浅色基调 */
  :root { color-scheme: light; }
}
