/* ============================================================
   盈亏日历 · Material 3 风格
   ============================================================ */
:root {
  --radius-s: 8px; --radius-m: 12px; --radius-l: 16px; --radius-xl: 28px;

  /* M3 light */
  --bg: #f7f5f9;
  --surface: #ffffff;
  --surface-2: #f3eef7;
  --surface-3: #ece6f0;
  --on-surface: #1c1b1f;
  --on-surface-variant: #49454f;
  --outline: #79747e;
  --outline-variant: #cac4d0;
  --primary: #0b57d0;
  --on-primary: #ffffff;
  --primary-container: #d3e3fd;
  --on-primary-container: #041e49;
  --secondary-container: #d8e2ff;
  --on-secondary-container: #001a41;
  --tertiary-container: #d5e0ff;
  --error: #b3261e;
  --error-container: #f9dedc;
  --on-error-container: #410e0b;
  --shadow-1: 0 1px 2px rgba(0,0,0,.08), 0 1px 3px 1px rgba(0,0,0,.06);
  --shadow-2: 0 2px 6px 2px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.12);

  /* 盈亏语义色：盈利绿 / 亏损红（文字点缀 + 浅色容器） */
  --pos-text: #157347;   --pos-bg: #d9f2e1;   --pos-border: #a8d8b8;
  --neg-text: #b3261e;   --neg-bg: #fde0dd;   --neg-border: #f2b8b5;
  /* 日历日期块：淡色填充（已平仓按盈亏着色；持仓中跨日用蓝） */
  --fill-gain-bg: #cdeede; --fill-gain-fg: #0f6b3a; --fill-gain-bd: #9fd9b4;
  --fill-loss-bg: #ffdad6; --fill-loss-fg: #b3261e; --fill-loss-bd: #f2b3ad;
  --fill-flat-bg: #ece9f0; --fill-flat-fg: #49454f; --fill-flat-bd: #d4cfda;
  --fill-span-bg: #d7e3ff; --fill-span-fg: #0b57d0; --fill-span-bd: #aac7ff;
  --open-chip-bg: #ffffff; --open-chip-text: #1c1b1f; --open-chip-border: #b6b2bc;

  --mono: "Roboto Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --sans: Roboto, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}
html[data-theme="dark"] {
  --bg: #141218;
  --surface: #1d1b20;
  --surface-2: #26232b;
  --surface-3: #2f2b34;
  --on-surface: #e6e0e9;
  --on-surface-variant: #cac4d0;
  --outline: #938f99;
  --outline-variant: #49454f;
  --primary: #aac7ff;
  --on-primary: #062e6f;
  --primary-container: #0842a0;
  --on-primary-container: #d3e3fd;
  --secondary-container: #3a4a75;
  --on-secondary-container: #d8e2ff;
  --tertiary-container: #30436e;
  --error: #ffb4ab;
  --error-container: #8c1d18;
  --on-error-container: #ffdad6;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4), 0 1px 3px 1px rgba(0,0,0,.3);
  --shadow-2: 0 2px 8px 2px rgba(0,0,0,.45);

  --pos-text: #8ce5ae;  --pos-bg: #123f27;   --pos-border: #2f7a46;
  --neg-text: #ffb4ab;  --neg-bg: #4a211d;   --neg-border: #8c3a34;
  --fill-gain-bg: #123f27; --fill-gain-fg: #8ce5ae; --fill-gain-bd: #2f7a46;
  --fill-loss-bg: #4a211d; --fill-loss-fg: #ffb4ab; --fill-loss-bd: #8c3a34;
  --fill-flat-bg: #2b2831; --fill-flat-fg: #cac4d0; --fill-flat-bd: #49454f;
  --fill-span-bg: #16387c; --fill-span-fg: #c6d8ff; --fill-span-bd: #3a63c4;
  --open-chip-bg: #2b2831; --open-chip-text: #e6e0e9; --open-chip-border: #49454f;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--on-surface);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: nowrap; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--outline-variant);
}
.app-logo {
  width: 40px; height: 40px; border-radius: 10px; flex: 0 0 auto;
  display: grid; place-items: center;
  overflow: hidden;
}
.app-logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.appbar-right { display: flex; flex-wrap: nowrap; align-items: center; gap: 4px; justify-content: flex-end; flex: 0 0 auto; }
/* 月份导航组：占满剩余宽度并居中，右侧是主题/头像 */
.appbar-center {
  display: flex; flex-wrap: nowrap; align-items: center; gap: 4px;
  flex: 1 1 auto; justify-content: center; min-width: 0;
}
.month-nav { flex-wrap: nowrap; }

.chip-btn, .icon-btn, .month-label, .fab, .btn, .btn-ghost, .btn-text, .btn-danger-text {
  border: none; cursor: pointer; font-family: inherit; color: var(--on-surface);
  background: transparent;
}
.chip-btn {
  height: 36px; padding: 0 16px; border-radius: 18px;
  font-size: 14px; font-weight: 500;
  background: var(--secondary-container); color: var(--on-secondary-container);
  transition: filter .15s;
}
.chip-btn:hover { filter: brightness(.97); }
.month-nav { display: flex; align-items: center; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; font-size: 20px; line-height: 1;
  display: grid; place-items: center; color: var(--on-surface);
  transition: background .15s;
}
.icon-btn:hover { background: var(--surface-3); }
.month-label {
  min-width: 118px; text-align: center; font-size: 15px; font-weight: 600;
  height: 40px; border-radius: 20px; padding: 0 10px;
}
.month-label:hover { background: var(--surface-3); }

.user-zone { display: flex; align-items: center; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
  background: var(--primary); color: var(--on-primary);
  display: grid; place-items: center; font-weight: 600; border: none;
}
.avatar.guest { background: var(--surface-3); color: var(--on-surface); }

/* ---------- 页面布局 ---------- */
.page { max-width: 1200px; margin: 0 auto; padding: 16px 16px 96px; }
.surface {
  background: var(--surface); border-radius: var(--radius-l);
  box-shadow: var(--shadow-1);
}

/* ---------- 汇总卡 ---------- */
.summary-card { padding: 14px 18px; margin-bottom: 16px; }
.summary-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.eyebrow { font-size: 13px; font-weight: 600; color: var(--on-surface-variant); letter-spacing: .3px; }
.summary-source { font-size: 12px; color: var(--on-surface-variant); }
.summary-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.stat-chip {
  display: flex; flex-direction: column; gap: 2px; min-width: 96px;
  padding: 8px 12px; border-radius: var(--radius-s);
  background: var(--surface-2);
}
.stat-chip .lab { font-size: 11px; color: var(--on-surface-variant); }
.stat-chip .val { font-family: var(--mono); font-size: 15px; font-weight: 600; }
.val.pos { color: var(--pos-text); }
.val.neg { color: var(--neg-text); }

/* ---------- 日历 ---------- */
.cal-card { padding: 12px; overflow: hidden; }
.cal-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr);
  margin-bottom: 8px;
}
.weekday {
  text-align: center; font-size: 12px; font-weight: 600;
  color: var(--on-surface-variant); padding: 6px 0;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.day-cell {
  position: relative;
  min-height: 108px;
  border-radius: var(--radius-m);
  background: var(--surface-2);
  border: 1px solid transparent;
  cursor: pointer; text-align: left; font-family: inherit;
  padding: 8px 8px 6px;
  display: flex; flex-direction: column; gap: 4px;
  transition: background .12s, transform .05s, box-shadow .12s;
  overflow: hidden;
}
.day-cell:hover { box-shadow: var(--shadow-1); }
.day-cell.out { background: transparent; cursor: default; box-shadow: none; }
.day-cell.out .dnum { color: var(--outline-variant); }
.day-cell.filled { background: var(--surface-2); }
/* 已平仓按盈亏：盈淡绿 / 亏淡红 / 平盘中性；未平仓（含未来平仓日）= 淡蓝 */
.day-cell.fill-gain { background: var(--fill-gain-bg); border-color: var(--fill-gain-bd); }
.day-cell.fill-loss { background: var(--fill-loss-bg); border-color: var(--fill-loss-bd); }
.day-cell.fill-flat { background: var(--fill-flat-bg); border-color: var(--fill-flat-bd); }
.day-cell.fill-span { background: var(--fill-span-bg); border-color: var(--fill-span-bd); }
.day-cell.fill-gain .dnum, .day-cell.fill-gain .day-pl { color: var(--fill-gain-fg); }
.day-cell.fill-loss .dnum, .day-cell.fill-loss .day-pl { color: var(--fill-loss-fg); }
.day-cell.fill-flat .dnum, .day-cell.fill-flat .day-pl { color: var(--fill-flat-fg); }
.day-cell.fill-span .dnum, .day-cell.fill-span .day-tag { color: var(--fill-span-fg); }
/* 半高模式：整格 = 一张卡片，内部上下两段无缝拼接（上未平仓淡蓝 / 下已结算盈亏色），
   日期融入上半段；外圆角/边框/形态与普通格子完全一致 */
.day-cell.dual { min-height: 160px; padding: 0; border-radius: var(--radius-m); border-color: var(--outline-variant); overflow: hidden; }
.day-cell.dual .du { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.day-cell.dual .du-seg {
  flex: 1 1 0; min-height: 0;
  display: flex; align-items: center; gap: 7px;
  padding: 3px 9px; overflow: hidden;
}
.day-cell.dual .du-open { background: var(--fill-span-bg); color: var(--fill-span-fg); }
.day-cell.dual .du-open .dnum { color: var(--fill-span-fg); flex: 0 0 auto; }
.day-cell.dual .du-open .day-chips { display: inline-flex; flex-wrap: nowrap; gap: 3px; margin: 0 0 0 auto; min-width: 0; }
.day-cell.dual .du-real.gain { background: var(--fill-gain-bg); color: var(--fill-gain-fg); }
.day-cell.dual .du-real.loss { background: var(--fill-loss-bg); color: var(--fill-loss-fg); }
.day-cell.dual .du-real.flat { background: var(--fill-flat-bg); color: var(--fill-flat-fg); }
.day-cell.dual .du-tag { font-size: 10px; font-weight: 600; letter-spacing: .5px; opacity: .9; white-space: nowrap; }
.day-cell.dual .du-pl { font-family: var(--mono); font-size: 19px; font-weight: 700; white-space: nowrap; }
.day-cell.dual .du-meta { font-family: var(--mono); font-size: 11px; opacity: .8; white-space: nowrap; }
.day-cell.dual .mini-chip.more { background: transparent; }
/* 跨日仓位相连：并拢相邻格、消除内侧圆角与中间分隔线（保留外轮廓） */
.day-cell.span-L { margin-left: -4px; border-top-left-radius: 0; border-bottom-left-radius: 0; border-left-color: transparent; }
.day-cell.span-R { border-top-right-radius: 0; border-bottom-right-radius: 0; border-right-color: transparent; }
.day-cell.today { box-shadow: inset 0 0 0 2px var(--primary); }
.day-cell.selected { box-shadow: inset 0 0 0 2px var(--on-surface-variant); }

.day-top { display: flex; justify-content: space-between; align-items: center; }
.dnum {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 14px; font-weight: 600; color: var(--on-surface);
}
.day-cell.today .dnum { background: var(--primary); color: var(--on-primary); font-weight: 600; }
.day-cell.out .dnum { background: transparent; }
.day-tag { font-size: 10px; color: var(--on-surface-variant); letter-spacing: .3px; }

.day-pl {
  font-family: var(--mono); font-size: 20px; font-weight: 700;
  line-height: 1.12; letter-spacing: -0.3px; white-space: nowrap;
}
.day-pl.pos { color: var(--pos-text); }
.day-pl.neg { color: var(--neg-text); }
.day-pl.flat { color: var(--on-surface); opacity: .82; }
.day-meta { font-family: var(--mono); font-size: 12px; color: var(--on-surface-variant); }
.day-chips { display: flex; flex-wrap: wrap; gap: 3px; margin-top: auto; align-content: flex-end; }
.mini-chip {
  font-size: 10px; line-height: 1; padding: 4px 7px; border-radius: 999px;
  border: 1px solid var(--outline-variant); background: var(--surface); color: var(--on-surface);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.mini-chip.open { background: var(--open-chip-bg); border-style: dashed; border-color: var(--open-chip-border); color: var(--open-chip-text); }
.mini-chip.more { border-style: none; color: var(--on-surface-variant); background: transparent; }

/* ---------- 图例 ---------- */
.legend {
  display: flex; flex-wrap: wrap; gap: 16px; justify-content: center;
  margin-top: 16px; color: var(--on-surface-variant); font-size: 12px;
}
.legend .lg { display: flex; align-items: center; gap: 6px; }
.lg-sq { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.lg-sq.gain { background: var(--fill-gain-bg); border: 1px solid var(--fill-gain-bd); }
.lg-sq.loss { background: var(--fill-loss-bg); border: 1px solid var(--fill-loss-bd); }
.lg-sq.span { background: var(--fill-span-bg); border: 1px solid var(--fill-span-bd); }

/* ---------- 悬浮按钮 ---------- */
.fab {
  position: fixed; right: 22px; bottom: 24px; z-index: 30;
  width: 60px; height: 60px; border-radius: 18px;
  background: var(--primary); color: var(--on-primary);
  font-size: 30px; font-weight: 400;
  box-shadow: var(--shadow-2); transition: transform .1s;
  display: grid; place-items: center;
}
.fab:hover { transform: scale(1.05); }
.fab:active { transform: scale(.96); }

/* ---------- 遮罩 & sheet ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,.45);
  animation: fadeIn .18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(640px, calc(100vw - 24px));
  max-height: min(86vh, 860px);
  z-index: 50;
  background: var(--surface); color: var(--on-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-2);
  display: flex; flex-direction: column; overflow: hidden;
  animation: popIn .18s cubic-bezier(.2,.8,.2,1);
}
@keyframes popIn {
  from { opacity: 0; transform: translate(-50%, -46%) scale(.98); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 18px 20px 4px;
}
.sheet-title { font-size: 20px; font-weight: 600; }
.sheet-body { padding: 12px 20px 8px; overflow-y: auto; }
.sheet-foot { padding: 12px 20px 18px; display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; padding: 3px 10px; border-radius: 999px; white-space: nowrap;
  background: var(--secondary-container); color: var(--on-secondary-container);
}
.pill.warn { background: var(--error-container); color: var(--on-error-container); }
.pill.neutral { background: var(--surface-3); color: var(--on-surface-variant); }
.pill.pos { background: var(--pos-bg); color: var(--pos-text); }
.pill.neg { background: var(--neg-bg); color: var(--neg-text); }

/* ---------- 六项指标网格 ---------- */
.metric-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  margin: 10px 0 6px;
}
.metric {
  border-radius: var(--radius-m); padding: 10px 12px;
  background: var(--surface-2);
}
.metric .lab { font-size: 11px; color: var(--on-surface-variant); margin-bottom: 3px; }
.metric .num { font-family: var(--mono); font-size: 16px; font-weight: 700; }
.metric .num.pos { color: var(--pos-text); }
.metric .num.neg { color: var(--neg-text); }
.note-line { font-size: 12px; color: var(--on-surface-variant); margin: 6px 0 2px; white-space: pre-wrap; }

/* ---------- 仓位列表 ---------- */
.pos-card {
  border: 1px solid var(--outline-variant); border-radius: var(--radius-m);
  padding: 10px 12px; margin-top: 10px;
}
.pos-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pos-sym { font-weight: 700; font-size: 14px; }
.pos-range { font-size: 12px; color: var(--on-surface-variant); font-family: var(--mono); }
.pos-note { font-size: 12px; color: var(--on-surface-variant); margin-top: 6px; }
.pos-perday {
  display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px;
  font-family: var(--mono); font-size: 12px;
}
.pos-perday b { font-weight: 600; }
.pos-total {
  margin-top: 6px; font-family: var(--mono); font-size: 11px;
  color: var(--on-surface-variant); border-top: 1px dashed var(--outline-variant);
  padding-top: 6px;
}
.pos-actions { display: flex; gap: 4px; margin-left: auto; }

.section-title {
  font-size: 13px; font-weight: 600; color: var(--on-surface-variant);
  margin: 16px 0 4px; letter-spacing: .4px;
}
.empty-hint { font-size: 13px; color: var(--on-surface-variant); padding: 14px 2px; }

/* ---------- 按钮 ---------- */
.btn {
  height: 40px; padding: 0 20px; border-radius: 20px;
  font-size: 14px; font-weight: 500;
  background: var(--primary); color: var(--on-primary);
  transition: filter .15s;
}
.btn:hover { filter: brightness(.96); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-ghost {
  height: 40px; padding: 0 16px; border-radius: 20px;
  font-size: 14px; font-weight: 500;
  background: var(--secondary-container); color: var(--on-secondary-container);
}
.btn-text { height: 40px; padding: 0 12px; border-radius: 20px; font-size: 14px; font-weight: 500; }
.btn-text:hover { background: var(--surface-3); }
.btn-danger-text { height: 36px; padding: 0 12px; border-radius: 18px; font-size: 13px; font-weight: 500; color: var(--error); }
.btn-danger-text:hover { background: var(--error-container); }
.icon-sm { width: 30px; height: 30px; border-radius: 50%; font-size: 13px; display: inline-grid; place-items: center; }
.icon-sm:hover { background: var(--surface-3); }

/* ---------- 表单 ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--on-surface-variant); margin-bottom: 6px; font-weight: 500; }
.field input[type="text"], .field input[type="password"], .field input[type="date"], .field input[type="number"] {
  width: 100%; height: 48px; padding: 0 14px;
  border-radius: var(--radius-s);
  border: 1px solid var(--outline-variant);
  background: var(--surface); color: var(--on-surface);
  font-family: inherit; font-size: 15px;
  outline: none;
}
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 25%, transparent); }
.field input.num { font-family: var(--mono); }
.form-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.field .hint { font-size: 11px; color: var(--outline); margin-top: 4px; }
@media (max-width: 560px) { .form-grid2 { grid-template-columns: 1fr; } }

/* ---------- 对话框 ---------- */
.dialog {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center; padding: 16px;
}
.dialog-scrim { position: absolute; inset: 0; background: rgba(0,0,0,.45); animation: fadeIn .16s ease; }
.dialog-card {
  position: relative; width: min(460px, 100%); max-height: 88vh; overflow-y: auto;
  background: var(--surface); color: var(--on-surface);
  border-radius: var(--radius-xl); padding: 22px;
  box-shadow: var(--shadow-2); animation: dlgIn .16s ease;
}
@keyframes dlgIn { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: scale(1); } }
.dialog-title { font-size: 20px; font-weight: 600; margin-bottom: 16px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }

/* ---------- 菜单 ---------- */
.menu {
  position: fixed; z-index: 70; min-width: 200px;
  background: var(--surface-3);
  border-radius: var(--radius-s); box-shadow: var(--shadow-2);
  padding: 6px; overflow: hidden;
}
.menu button {
  display: block; width: 100%; text-align: left;
  padding: 10px 14px; border: none; background: none; cursor: pointer;
  font-family: inherit; font-size: 14px; color: var(--on-surface);
  border-radius: 6px;
}
.menu button:hover { background: var(--surface); }
.menu button.danger { color: var(--error); }
.menu .menu-sep { height: 1px; background: var(--outline-variant); margin: 4px 6px; }

/* ---------- toast ---------- */
.toasts { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--on-surface); color: var(--surface);
  padding: 10px 18px; border-radius: 999px; font-size: 13px;
  box-shadow: var(--shadow-2); max-width: 86vw;
  animation: fadeIn .15s ease;
}

/* ---------- 管理端登录页 ---------- */
.login-screen {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: 20px; background: var(--bg);
  overflow-y: auto;
}
.login-card { width: min(400px, 100%); padding: 34px 30px 30px; border-radius: 28px; }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.login-title { font-size: 20px; font-weight: 600; }
.login-sub { font-size: 13px; color: var(--on-surface-variant); margin-top: 2px; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 60px; }
.pw-eye {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: none; background: transparent; cursor: pointer;
  color: var(--primary); font-size: 12px; font-weight: 600;
  padding: 8px 10px; border-radius: 8px; font-family: inherit;
}
.pw-eye:hover { background: var(--surface-3); }
.login-err {
  color: var(--error); font-size: 13px; margin: 2px 0 14px;
  background: var(--error-container); border-radius: 10px; padding: 10px 12px;
}
.login-btn { width: 100%; height: 48px; border-radius: 24px; font-size: 15px; margin-top: 4px; }
body.gated .appbar, body.gated main, body.gated #fab { display: none !important; }

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--outline-variant); border-radius: 4px; }

/* ============================================================
   移动端自适应（手机优先：触控、留白、字号、安全区）
   ============================================================ */
/* 触控优化 */
.icon-btn, .chip-btn, .month-label, .avatar, .day-cell, .fab, .btn, .btn-ghost, .btn-text, .btn-danger-text,
.menu button, .pw-eye, .icon-sm {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.day-cell { user-select: none; }

/* ---------- ≤700px：平板竖屏 / 大屏手机 ---------- */
@media (max-width: 700px) {
  body { overflow-x: hidden; }

  /* 顶栏单行：月份导航居中，主题/头像靠右 */
  .appbar {
    padding: calc(6px + env(safe-area-inset-top)) 10px 6px;
  }
  .icon-btn { width: 34px; height: 34px; font-size: 17px; flex: 0 0 auto; }
  .chip-btn { height: 32px; padding: 0 11px; font-size: 12.5px; flex: 0 0 auto; }
  .month-label {
    min-width: 0; width: clamp(64px, 19vw, 120px); height: 32px;
    font-size: 13.5px; padding: 0 4px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .month-nav .icon-btn { width: 30px; height: 32px; }
  .avatar { width: 34px; height: 34px; font-size: 13px; flex: 0 0 auto; }
  .user-zone { flex: 0 0 auto; }

  /* 页面留白收紧 */
  .page { padding: 10px 8px calc(86px + env(safe-area-inset-bottom)); }

  /* 汇总 chips → 自适应网格，避免超长金额撑破 */
  .summary-card { padding: 12px; margin-bottom: 10px; }
  .summary-head { gap: 6px; margin-bottom: 8px; }
  .summary-chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
  .stat-chip { min-width: 0; padding: 7px 10px; }
  .stat-chip .lab { font-size: 10px; }
  .stat-chip .val { font-size: 13px; white-space: nowrap; }

  /* 日历：更小内边距，腾出数字宽度 */
  .cal-card { padding: 6px; }
  .cal-weekdays { margin-bottom: 3px; }
  .weekday { font-size: 11px; padding: 4px 0; }
  .cal-grid { gap: 3px; }
  .day-cell {
    min-height: 80px;
    padding: 3px 3px 2px;
    border-radius: 10px;
    gap: 2px;
  }
  .day-cell.span-L { margin-left: -3px; }
  .day-cell.dual { min-height: 104px; padding: 0; }
  .day-cell.dual .du-seg { gap: 5px; padding: 1px 4px; }
  .day-cell.dual .du-tag { font-size: 9px; }
  .day-cell.dual .du-meta { font-size: 10px; }
  .dnum { width: 22px; height: 22px; font-size: 12.5px; }
  .day-cell.dual .dnum { width: 20px; height: 20px; font-size: 12px; }
  .day-pl { font-size: 16px; }
  .day-meta { font-size: 10px; }
  .day-tag { font-size: 9px; }

  .legend { gap: 8px 14px; margin-top: 12px; font-size: 11px; }

  /* FAB / toast 抬升，避开底部安全区 */
  .fab {
    right: 16px; bottom: calc(18px + env(safe-area-inset-bottom));
    width: 56px; height: 56px; border-radius: 16px; font-size: 27px;
  }
  .toasts { bottom: calc(18px + env(safe-area-inset-bottom)); }
}

/* ---------- ≤560px：常规手机 ---------- */
@media (max-width: 560px) {
  .day-cell { min-height: 66px; }
  .day-cell.dual { min-height: 92px; }
  .day-pl { font-size: 14px; }

  /* 表单字号抬到 16px，避免 iOS 聚焦自动放大 */
  .field input[type="text"], .field input[type="password"],
  .field input[type="date"], .field input[type="number"] { font-size: 16px; }

  /* 六项指标 → 2 列 */
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .metric { padding: 9px 10px; }
  .metric .num { font-size: 15px; }

  .pos-card { padding: 9px 10px; }
  .pos-top { gap: 6px; }

  /* 对话框 → 底部抽屉式（贴底 + 圆角顶 + 安全区） */
  .dialog { padding: 0; align-items: flex-end; }
  .dialog-card {
    width: 100%; max-height: 92dvh;
    border-radius: 20px 20px 0 0;
    padding: 20px 18px calc(16px + env(safe-area-inset-bottom));
  }

  .login-screen { padding: 16px; align-items: flex-end; }
  .login-card { width: 100%; padding: 24px 20px calc(20px + env(safe-area-inset-bottom)); }

  .sheet-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
}

/* ---------- ≤460px：窄屏手机 → 日详情/弹层改底部面板 ---------- */
@media (max-width: 460px) {
  .sheet {
    left: 0; right: 0; top: auto; bottom: 0;
    transform: none; width: 100%;
    max-height: min(92dvh, 92vh);
    border-radius: 24px 24px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    animation: sheetUp .22s cubic-bezier(.2,.8,.2,1);
  }
  @keyframes sheetUp {
    from { opacity: .4; transform: translateY(26px); }
    to   { opacity: 1; transform: none; }
  }
  .sheet-head { padding: 16px 16px 2px; }
  .sheet-body { padding: 10px 16px 8px; }
  .sheet-title { font-size: 18px; }
}

/* ---------- ≤400px：小屏细节收敛 ---------- */
@media (max-width: 400px) {
  .day-cell { min-height: 60px; }
  .day-cell.dual { min-height: 86px; }
  .day-cell.dual .du-tag,
  .day-tag { display: none; }   /* 格内容纳不下“持仓中”文字，交给色块与图例表达 */
  .legend .lg:last-child { display: none; }
  .stat-chip .val { font-size: 12px; }
}
