/* 股票日记样式 — 暗色主题为主，自适应桌面/手机 */

:root {
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-elev-2: #1c232c;
  --border: #2a313c;
  --text: #e6edf3;
  --text-dim: #9aa4b0;
  --muted: #6e7681;
  --primary: #58a6ff;
  --primary-bg: #1f6feb;
  --danger: #f85149;
  --accent: #f0883e;

  --hm-0: #21262d;          /* 比卡片底色亮一档，空格子也看得见 */
  --hm-1: #0e4429;
  --hm-2: #006d32;
  --hm-3: #26a641;
  --hm-4: #39d353;
  --hm-border: rgba(255,255,255,0.08);

  --radius: 8px;
  --shadow: 0 6px 24px rgba(0,0,0,0.3);

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #fafbfc;
    --bg-elev: #ffffff;
    --bg-elev-2: #f4f5f7;
    --border: #d0d7de;
    --text: #1f2328;
    --text-dim: #57606a;
    --muted: #8c959f;
    --primary: #0969da;
    --primary-bg: #0969da;
    --hm-0: #ebedf0;
    --hm-1: #9be9a8;
    --hm-2: #40c463;
    --hm-3: #30a14e;
    --hm-4: #216e39;
    --hm-border: rgba(27,31,35,0.10);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
  /* PWA 全屏模式下，左右刘海区域也别让内容贴边 */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── 顶栏 ──────────────────────────────────────────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  /* PWA 安装到桌面后，顶部要避开手机状态栏（刘海/灵动岛） */
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(13, 17, 23, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
@media (prefers-color-scheme: light) {
  .topbar { background: rgba(255, 255, 255, 0.85); }
}
.brand { font-weight: 600; font-size: 16px; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.search { flex: 1; max-width: 420px; }
.search input {
  width: 100%; padding: 8px 12px;
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; outline: none;
}
.search input:focus { border-color: var(--primary); }
.top-actions { display: flex; gap: 8px; margin-left: auto; }

/* ── 按钮 ──────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-elev-2);
  color: var(--text); font-size: 14px; cursor: pointer;
  text-decoration: none; user-select: none;
}
.btn:hover { background: var(--bg-elev); border-color: var(--primary); text-decoration: none; }
.btn.primary { background: var(--primary-bg); border-color: var(--primary-bg); color: white; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

#logout-btn svg { display: block; }
/* 窄屏下登出按钮只留图标，省地方；图标本身已经能表意 */
@media (max-width: 768px) {
  #logout-btn .btn-label { display: none; }
}

/* ── 主区 ──────────────────────────────────────────────────────────── */

main#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 96px;
}
.loading, .empty {
  padding: 60px 20px; text-align: center; color: var(--muted);
}

/* ── 首页 ──────────────────────────────────────────────────────────── */

.home-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.home-head h2 { margin: 0; font-size: 20px; }
.year-nav { display: flex; gap: 6px; }
.year-nav .btn { padding: 4px 10px; }

.heatmap-wrap {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 24px;
}

.hm-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.hm { display: block; min-width: 100%; }
.hm-cell {
  fill: var(--hm-0);
  stroke: var(--hm-border);
  stroke-width: 1;
  cursor: pointer;
  transition: stroke 0.15s;
}
.hm-cell.lv-1 { fill: var(--hm-1); }
.hm-cell.lv-2 { fill: var(--hm-2); }
.hm-cell.lv-3 { fill: var(--hm-3); }
.hm-cell.lv-4 { fill: var(--hm-4); }
.hm-cell.out { opacity: 0.25; cursor: default; }
.hm-cell.today { stroke: var(--primary); stroke-width: 1.5; }
.hm-cell:hover { stroke: var(--text); stroke-width: 1.2; }
.hm-month, .hm-dow {
  font-size: 10px; fill: var(--muted); font-family: inherit;
}

.hm-legend {
  display: flex; align-items: center; gap: 6px;
  margin-top: 10px; font-size: 12px; color: var(--muted);
}
.hm-sw {
  width: 12px; height: 12px; border-radius: 2px;
  background: var(--hm-0); display: inline-block;
  border: 1px solid var(--hm-border); box-sizing: border-box;
}
.hm-sw.lv-1 { background: var(--hm-1); }
.hm-sw.lv-2 { background: var(--hm-2); }
.hm-sw.lv-3 { background: var(--hm-3); }
.hm-sw.lv-4 { background: var(--hm-4); }

.section-title { font-size: 16px; margin: 24px 0 12px; }
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.card {
  display: block; padding: 14px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  transition: transform 0.1s, border-color 0.1s;
}
.card:hover { transform: translateY(-2px); border-color: var(--primary); text-decoration: none; }
.card-meta {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px; font-size: 12px; color: var(--muted);
}
.card-date { font-variant-numeric: tabular-nums; }
.card-tickers { display: flex; gap: 4px; flex-wrap: wrap; }
.card-title { font-weight: 600; margin-bottom: 6px; }
.card-preview {
  color: var(--text-dim); font-size: 13px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-foot { margin-top: 8px; font-size: 11px; }

.chip {
  display: inline-block; padding: 2px 8px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: 999px; font-size: 11px; color: var(--primary);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.chip:hover { background: var(--primary-bg); color: white; text-decoration: none; border-color: var(--primary-bg); }

/* ── 当天视图 ──────────────────────────────────────────────────────── */

.day-head, .home-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.day-head h2 { margin: 0; font-size: 20px; flex: 1; }
.back {
  background: transparent; border: none; color: var(--primary);
  font-size: 14px; cursor: pointer; padding: 4px 8px;
}

.note {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  margin-bottom: 16px;
}
.note-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px; margin-bottom: 12px;
}
.note-head h3 { margin: 0; font-size: 18px; }
.note-meta { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.note-foot { margin-top: 16px; font-size: 12px; border-top: 1px solid var(--border); padding-top: 10px; }

/* ── Markdown 渲染 ──────────────────────────────────────────────── */

.md { color: var(--text); }
.md h1, .md h2, .md h3, .md h4 { margin: 1.2em 0 0.5em; line-height: 1.3; }
.md h1 { font-size: 1.5em; }
.md h2 { font-size: 1.3em; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.md h3 { font-size: 1.15em; }
.md p { margin: 0.6em 0; }
.md ul, .md ol { padding-left: 1.6em; margin: 0.6em 0; }
.md li { margin: 0.2em 0; }
.md blockquote {
  border-left: 3px solid var(--primary);
  padding: 4px 12px; margin: 0.8em 0;
  background: var(--bg-elev-2); color: var(--text-dim);
}
.md code {
  background: var(--bg-elev-2);
  padding: 2px 6px; border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 0.92em;
}
.md pre {
  background: var(--bg-elev-2); border: 1px solid var(--border);
  padding: 12px 14px; border-radius: var(--radius);
  overflow-x: auto;
}
.md pre code { background: transparent; padding: 0; }
.md table { border-collapse: collapse; margin: 0.8em 0; width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; }
.md th { background: var(--bg-elev-2); }
.md a { word-break: break-word; }
.md img { max-width: 100%; height: auto; border-radius: 4px; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }
.md input[type="checkbox"] { transform: translateY(2px); margin-right: 4px; }

/* ── 股票视图：timeline ──────────────────────────────────────────── */

.timeline { border-left: 2px solid var(--border); margin-left: 12px; padding-left: 18px; }
.tl-item {
  display: block; position: relative;
  padding: 12px 14px; margin-bottom: 12px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
}
.tl-item::before {
  content: ''; position: absolute; left: -25px; top: 18px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--primary); border: 2px solid var(--bg);
}
.tl-item:hover { border-color: var(--primary); text-decoration: none; transform: translateX(2px); transition: 0.1s; }
.tl-date { font-size: 12px; color: var(--muted); margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.tl-title { font-weight: 600; }
.tl-preview { font-size: 13px; margin-top: 4px; }

/* ── 编辑器 ──────────────────────────────────────────────────────── */

.editor { display: flex; flex-direction: column; gap: 12px; }
.ed-actions { display: flex; gap: 8px; }

.ed-fields { display: flex; flex-direction: column; gap: 10px; }
.ed-title {
  width: 100%; padding: 12px 14px; font-size: 18px; font-weight: 500;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
}
.ed-title:focus { outline: none; border-color: var(--primary); }

.ed-meta {
  display: flex; gap: 12px; flex-wrap: wrap;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px;
}
.ed-date-wrap { display: flex; align-items: center; gap: 8px; }
.ed-date-wrap input {
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px;
  font-family: inherit; font-size: 14px;
  color-scheme: dark;
}
.ed-tickers {
  display: flex; align-items: center; gap: 6px; flex: 1; flex-wrap: wrap;
}
.ed-tickers-label { white-space: nowrap; }
.chip-list { display: contents; }
.chip.removable {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--primary-bg); color: white; border-color: var(--primary-bg);
}
.chip.removable button {
  background: none; border: none; color: white; cursor: pointer;
  padding: 0; font-size: 14px; line-height: 1;
}
.ed-ticker-wrap {
  position: relative; flex: 1; min-width: 140px;
}
#ed-ticker-input {
  width: 100%; padding: 4px 8px;
  background: transparent; border: none; color: var(--text);
  font-size: 14px; outline: none;
}

.ed-suggest {
  position: absolute; top: calc(100% + 6px); left: -6px;
  min-width: 240px; max-width: 320px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  z-index: 30; padding: 4px;
  overflow: hidden;
}
.ed-suggest-title {
  padding: 8px 10px 6px; font-size: 11px;
  color: var(--muted); letter-spacing: 0.02em;
}
.ed-suggest-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 6px;
  cursor: pointer; user-select: none;
}
.ed-suggest-item.active, .ed-suggest-item:hover {
  background: var(--bg-elev-2);
}
.ed-suggest-sym {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-weight: 600; color: var(--primary); flex-shrink: 0;
}
.ed-suggest-count { font-size: 12px; flex: 1; }
.ed-suggest-x {
  background: none; border: none; color: var(--muted);
  font-size: 16px; line-height: 1; cursor: pointer;
  padding: 2px 6px; border-radius: 4px;
  opacity: 0; transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.ed-suggest-item:hover .ed-suggest-x,
.ed-suggest-item.active .ed-suggest-x { opacity: 1; }
.ed-suggest-x:hover { color: var(--danger); background: rgba(248, 81, 73, 0.12); }

/* 手机端 × 始终可见，hover 不可用 */
@media (max-width: 768px) {
  .ed-suggest-x { opacity: 0.7; }
  .ed-suggest { width: 100%; max-width: none; }
}

.ed-toolbar {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 6px; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: var(--radius);
  position: sticky; top: 56px; z-index: 5;
}
.ed-btn {
  padding: 6px 9px; background: transparent;
  border: 1px solid transparent; border-radius: 4px;
  color: var(--text); cursor: pointer; font-size: 13px;
  font-family: ui-monospace, monospace; min-width: 32px;
}
.ed-btn:hover { background: var(--bg-elev-2); border-color: var(--border); }
.ed-tab {
  margin-left: auto; padding: 6px 9px; background: transparent;
  border: 1px solid var(--border); border-radius: 4px;
  color: var(--text); cursor: pointer; font-size: 13px; display: none;
}
.ed-tab[data-tab="help"] { display: inline-flex; margin-left: 8px; }

.ed-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  min-height: 60vh;
}
.ed-textarea {
  width: 100%; min-height: 60vh; padding: 14px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 14px; line-height: 1.6; resize: vertical;
}
.ed-textarea:focus { outline: none; border-color: var(--primary); }
.ed-preview {
  padding: 14px; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow-y: auto; max-height: 80vh;
}
.ed-help {
  display: none; padding: 14px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-dim);
  grid-column: 1 / -1;
}
.ed-help pre {
  background: var(--bg); border: 1px solid var(--border);
  padding: 12px; border-radius: 6px; font-size: 12px;
  white-space: pre-wrap;
}
.ed-status { font-size: 12px; }

/* ── 浮动按钮（手机） ─────────────────────────────────────────────── */

.fab {
  position: fixed; bottom: 20px; right: 20px;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary-bg); color: white;
  display: none; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 300; text-decoration: none;
  box-shadow: var(--shadow); z-index: 20;
  bottom: calc(20px + env(safe-area-inset-bottom));
}
.fab:hover { text-decoration: none; }

/* ── 登录页 ──────────────────────────────────────────────────────── */

.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  /* 登录页在 PWA 里也要避开状态栏 */
  padding-top: env(safe-area-inset-top);
}
.login-card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px; width: 320px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 8px; font-size: 22px; text-align: center; }
.login-card .muted { text-align: center; margin: 0 0 20px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; }
.login-card input {
  padding: 10px 12px; background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 15px;
}
.login-card input:focus { outline: none; border-color: var(--primary); }
.login-card button {
  padding: 10px; background: var(--primary-bg); color: white;
  border: none; border-radius: var(--radius); font-size: 15px;
  cursor: pointer; font-weight: 500;
}
.login-card button:hover { filter: brightness(1.1); }
.err { color: var(--danger); font-size: 13px; text-align: center; }

/* ── 通用 ────────────────────────────────────────────────────────── */

.muted { color: var(--muted); }

/* ── PWA 安装入口 ────────────────────────────────────────────────── */

#install-btn { font-size: 13px; }

.ios-install-hint {
  position: fixed; left: 0; right: 0;
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex; justify-content: center; pointer-events: none;
  z-index: 100;
}
.ios-install-card {
  pointer-events: auto;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px 44px 14px 16px;
  box-shadow: var(--shadow);
  max-width: 92vw; position: relative;
  font-size: 14px; color: var(--text);
  animation: slideUp 0.25s ease-out;
}
.ios-install-title { font-weight: 600; margin-bottom: 6px; }
.ios-install-step {
  display: flex; align-items: center; gap: 6px;
  color: var(--text-dim); font-size: 13px; line-height: 1.5;
}
.ios-install-step svg { color: var(--primary); flex-shrink: 0; }
.ios-install-close {
  position: absolute; top: 6px; right: 8px;
  background: none; border: none; color: var(--muted);
  font-size: 22px; line-height: 1; cursor: pointer;
  padding: 4px 8px;
}
.ios-install-close:hover { color: var(--text); }

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

/* iOS 安装提示和 FAB 同时显示时，把 FAB 顶上去一些避免互相遮 */
.ios-install-hint ~ .fab,
body:has(.ios-install-hint) .fab {
  bottom: calc(140px + env(safe-area-inset-bottom));
}

/* ── 响应式 (≤ 768px) ─────────────────────────────────────────────── */

@media (max-width: 768px) {
  body { font-size: 14px; }
  .topbar { padding: calc(8px + env(safe-area-inset-top)) 12px 8px; flex-wrap: wrap; }
  .brand { font-size: 14px; }
  .search { order: 3; flex-basis: 100%; max-width: none; margin-top: 4px; }
  .topbar .top-actions .btn.primary { display: none; }  /* 顶栏「写笔记」用 FAB 代替；笔记页「编辑」不受影响 */
  main#app { padding: 14px 12px 100px; }

  .home-head h2 { font-size: 17px; }

  .ed-toolbar { top: 0; position: sticky; }
  .ed-grid {
    grid-template-columns: 1fr;
    min-height: auto;
  }
  .ed-tab { display: inline-flex; }
  .ed-grid[data-show="preview"] .ed-textarea { display: none; }
  .ed-grid[data-show="preview"] .ed-preview { display: block; }
  .ed-grid[data-show="edit"] .ed-preview { display: none; }
  .ed-grid[data-show="help"] .ed-textarea,
  .ed-grid[data-show="help"] .ed-preview { display: none; }
  .ed-grid[data-show="help"] .ed-help { display: block; }
  .ed-grid:not([data-show]) .ed-preview { display: none; }  /* 默认只看编辑 */
  .ed-textarea { min-height: 55vh; }

  .fab { display: flex; }
  .note-head { flex-direction: column; align-items: stretch; }
  .ed-meta { flex-direction: column; align-items: stretch; }
}

/* 平板默认隐藏 FAB（桌面用顶栏 ✏️ 按钮） */
@media (min-width: 769px) {
  .fab { display: none !important; }
}
