/* =========================================================================
 * 設計代號（Design tokens）
 * 淺色為預設；深色為另外挑選並驗證過的色階，不是自動反轉
 * ========================================================================= */
:root {
  color-scheme: light;
  --bg: #EEF1F6;            /* 頁面底色 */
  --surface: #FFFFFF;       /* 卡片 */
  --surface-2: #F6F8FB;     /* 卡片內的次要區塊、表頭 */
  --surface-3: #EDF1F7;     /* 按下、選取 */
  --line: #E3E8F0;
  --line-strong: #CDD5E1;
  --ink: #0F1B2D;           /* 主要文字 */
  --ink-2: #3D4C63;         /* 次要文字 */
  --muted: #5A6B82;         /* 說明文字 */
  --accent: #1F4F99;        /* 連結、焦點 */
  --accent-tint: #E8EEF8;
  --hero: #10243E;          /* 總覽英雄區底色 */
  --hero-2: #1A3557;
  --hero-ink: #FFFFFF;
  --hero-muted: #B9C6D8;
  --hero-gain: #FF8C9B;
  --hero-loss: #6FE0A6;
  --hero-brass: #F2C46B;
  --gain: #C8102E;          /* 上漲、獲利（台股慣例為紅） */
  --loss: #1B7F4D;          /* 下跌、虧損（綠） */
  --brass: #B26A00;         /* 股息：已入帳（實心） */
  --brass-soft: #E9C98F;    /* 股息：預計（淺色） */
  --brass-tint: #FBF1E0;
  --brass-ink: #8A5200;
  --ok-tint: #E6F2EB;   --ok-ink: #14663D;
  --warn-tint: #FBF1E0; --warn-ink: #8A5200;
  --bad-tint: #FCE8EA;  --bad-ink: #A30D25;
  /* 股票類別色（--cat-<代號>）由網站依資料庫的類別設定產生（CategoryStyles），這裡只放固定用途的顏色 */
  --src-dca: #2E63B8;         /* 買進來源：定期定額 */
  --src-manual: #7C4DBA; --src-manual-tint: #F1EBFA; --src-manual-ink: #5E3A96;   /* 買進來源：手動 */
  --bench: #2E63B8;           /* 和大盤比較：同期買大盤的線 */
  --grid: #E9EDF3;          /* 圖表格線 */
  --switch-off: #7C8BA1;    /* 開關關閉時的軌道色 */
  --scroll-thumb: rgba(61, 76, 99, .28);       /* 捲軸 */
  --scroll-thumb-hover: rgba(61, 76, 99, .55);
  --shadow-sm: 0 1px 2px rgba(15, 27, 45, .05);
  --shadow-md: 0 6px 24px -8px rgba(15, 27, 45, .18);
  --shadow-lg: 0 24px 60px -20px rgba(15, 27, 45, .35);
  --scrim: rgba(15, 27, 45, .42);

  --font: 'Noto Sans TC', system-ui, -apple-system, 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  --font-num: 'Manrope', 'Noto Sans TC', system-ui, sans-serif;
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --ease-spring: cubic-bezier(.3, 1.3, .5, 1);
  --side-w: 236px;
  --gutter: 32px;
  --tabbar-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0D1522; --surface: #141E2E; --surface-2: #1A2638; --surface-3: #223049;
    --line: #26344A; --line-strong: #34465F;
    --ink: #E9EEF6; --ink-2: #C0CBDB; --muted: #94A3B8;
    --accent: #8DB4F5; --accent-tint: #1A2A47;
    --hero: #172A45; --hero-2: #20385A;
    --gain: #FF7085; --loss: #4CC38A;
    --brass: #BE8526; --brass-soft: #6E5426; --brass-tint: #2E2416; --brass-ink: #E6B566;
    --ok-tint: #15301F; --ok-ink: #6FD39B; --warn-tint: #33270F; --warn-ink: #F0B85A; --bad-tint: #3A1A20; --bad-ink: #FF8A98;
    --src-dca: #4F7ED4; --src-manual: #8F6FD3; --src-manual-tint: #2A2242; --src-manual-ink: #C3B0F2; --bench: #4F7ED4;
    --grid: #223047; --switch-off: #64758F; --scroll-thumb: rgba(192, 203, 219, .25); --scroll-thumb-hover: rgba(192, 203, 219, .5);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 8px 28px -10px rgba(0, 0, 0, .6);
    --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, .7);
    --scrim: rgba(3, 8, 16, .6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0D1522; --surface: #141E2E; --surface-2: #1A2638; --surface-3: #223049;
  --line: #26344A; --line-strong: #34465F;
  --ink: #E9EEF6; --ink-2: #C0CBDB; --muted: #94A3B8;
  --accent: #8DB4F5; --accent-tint: #1A2A47;
  --hero: #172A45; --hero-2: #20385A;
  --gain: #FF7085; --loss: #4CC38A;
  --brass: #BE8526; --brass-soft: #6E5426; --brass-tint: #2E2416; --brass-ink: #E6B566;
  --ok-tint: #15301F; --ok-ink: #6FD39B; --warn-tint: #33270F; --warn-ink: #F0B85A; --bad-tint: #3A1A20; --bad-ink: #FF8A98;
  --src-dca: #4F7ED4; --src-manual: #8F6FD3; --src-manual-tint: #2A2242; --src-manual-ink: #C3B0F2; --bench: #4F7ED4;
  --grid: #223047; --switch-off: #64758F; --scroll-thumb: rgba(192, 203, 219, .25); --scroll-thumb-hover: rgba(192, 203, 219, .5);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 8px 28px -10px rgba(0, 0, 0, .6);
  --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, .7);
  --scrim: rgba(3, 8, 16, .6);
}

/* =========================================================================
 * 基礎
 * ========================================================================= */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 15px; line-height: 1.6;
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
/* 手機上方安全區域的底色帶，避免捲動內容露出在瀏海後面 */
body::before {
  content: ''; position: fixed; inset: 0 0 auto 0; height: env(safe-area-inset-top, 0px);
  background: var(--surface); z-index: 60;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
/* 換頁時 Blazor 把焦點移到標題（FocusOnNavigate，給螢幕閱讀器用），標題本身不需要外框 */
h1[tabindex="-1"]:focus { outline: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: .01em; }
p { margin: 0; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-feature-settings: 'tnum' 1; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.gain { color: var(--gain); }
.loss { color: var(--loss); }
.brass { color: var(--brass-ink); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
/* 切換分頁時新內容淡入（以 @key 重建元素觸發） */
.panel-in { animation: rise .3s var(--ease-out) backwards; }
.nowrap { white-space: nowrap; }
svg { display: block; }
.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ic.sm { width: 16px; height: 16px; }

/* =========================================================================
 * 捲軸：細、圓角、平常低調，滑過時加深
 * Chrome / Edge / Safari 用 ::-webkit-scrollbar；不支援的瀏覽器（Firefox）改用標準屬性
 * ========================================================================= */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 999px; border: 3px solid transparent; background-clip: padding-box; min-height: 40px; }
::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); border-width: 2px; background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }
@supports not selector(::-webkit-scrollbar) {
  * { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
}

/* =========================================================================
 * 版面骨架：桌機側欄、平板窄欄、手機上方列與下方分頁
 * ========================================================================= */
.side {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w); z-index: 40;
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 22px 14px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; color: var(--ink); }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; background: var(--hero); color: var(--hero-brass);
  display: grid; place-items: center; flex: none;
}
.brand-name { font-weight: 700; font-size: 16px; line-height: 1.2; }
.brand-sub { font-size: 12px; color: var(--muted); }
.nav { position: relative; display: flex; flex-direction: column; gap: 2px; }
.nav a {
  position: relative; z-index: 1; display: flex; align-items: center; gap: 12px;
  height: 44px; padding: 0 12px; border-radius: 10px; color: var(--ink-2); font-weight: 500;
  transition: color .2s;
}
.nav a:hover { text-decoration: none; color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); font-weight: 700; }
.nav a[aria-current="page"] .ic { color: var(--accent); }
/* 側欄的選取底色，會滑動到目前頁面 */
.nav-ind {
  position: absolute; left: 0; right: 0; top: 0; height: 44px; border-radius: 10px;
  background: var(--accent-tint); transition: transform .42s var(--ease-out), opacity .2s;
}
.nav-ind::before { content: ''; position: absolute; left: -14px; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.side-foot { margin-top: auto; display: grid; gap: 10px; }
.sync {
  display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 12px;
  background: var(--surface-2); font-size: 12.5px; color: var(--ink-2); line-height: 1.4;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok-ink); flex: none; position: relative; }
.dot.live::after {
  content: ''; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid var(--ok-ink);
  opacity: 0; animation: ping 2.4s var(--ease-out) 1s 3;
}
.user { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 12px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent-tint); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none;
}
.user-mail { font-size: 12.5px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }

.main {
  margin-left: var(--side-w); min-height: 100dvh;
  padding: 28px var(--gutter) 64px;
}
.page { max-width: 1240px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-title { font-size: 26px; line-height: 1.25; }
.page-sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
/* 系統 → 偏好與存取的遮蔽金額開關：和上面的外觀用細線分開 */
.mask-row { display: flex; gap: 12px; align-items: flex-start; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
/* 遮蔽金額時，AI 助理的回答（金額是模型寫的文字，不經過網站的格式化）整段模糊顯示 */
html[data-mask="1"] .ans { filter: blur(7px); user-select: none; }
/* 持股頁「期間表現」：自訂區間的日期、含息與不含息兩個大數字、說明 */
.period-range { display: grid; grid-template-columns: repeat(2, minmax(0, 190px)); gap: 12px; padding: 12px 20px 0; }
.period-range .field { margin: 0; min-width: 0; }
.period-range .input { width: 100%; min-width: 0; }
.period-error { padding: 12px 20px 16px; margin: 0; }
.period-sum { display: grid; grid-template-columns: repeat(2, minmax(0, max-content)); gap: 8px 40px; padding: 14px 20px 14px; align-items: end; }
.period-fig { display: grid; gap: 2px; }
.period-fig .k { font-size: 13px; color: var(--muted); }
.period-fig b { font-size: 24px; font-weight: 800; line-height: 1.25; }
.period-fig > span.num { font-size: 13.5px; font-weight: 700; }
.period-note { grid-column: 1 / -1; margin: 4px 0 0; }
@media (max-width: 640px) { .period-range { grid-template-columns: repeat(2, minmax(0, 1fr)); } .period-sum { gap: 8px 20px; } .period-fig b { font-size: 20px; } }
/* 股息頁的年度選擇：只放年份，不用撐滿整列 */
.year-pick .dd { width: 140px; }
/* 個股頁右上角的現價：手機上改為獨立一列、靠左，價格與漲跌並排 */
.stock-price { text-align: right; }
.stock-price .num.big { font-size: 32px; font-weight: 800; line-height: 1.1; }

.topbar, .tabbar { display: none; }

/* 平板：側欄縮成圖示欄 */
@media (max-width: 1099px) {
  :root { --side-w: 84px; --gutter: 24px; }
  .side { padding: 18px 10px; align-items: stretch; }
  .brand { justify-content: center; padding: 4px 0 18px; }
  .brand-text, .user-mail, .sync-text { display: none; }
  .nav a { flex-direction: column; justify-content: center; gap: 2px; height: 58px; padding: 0; font-size: 11.5px; }
  .nav-ind { height: 58px; }
  .nav-ind::before { left: -10px; }
  .sync { justify-content: center; padding: 10px; }
  .user { justify-content: center; }
}

/* 手機：上方列 + 下方分頁列 */
@media (max-width: 719px) {
  :root { --gutter: 16px; }
  .side { display: none; }
  .main {
    margin-left: 0;
    padding: 12px max(16px, env(safe-area-inset-right, 0px)) calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: env(safe-area-inset-top, 0px); z-index: 45;
    height: 56px; padding: 0 max(12px, env(safe-area-inset-right, 0px)) 0 max(12px, env(safe-area-inset-left, 0px));
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
    border-bottom: 1px solid var(--line);
  }
  .topbar-title { font-weight: 700; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .sync-mini { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; z-index: 45;
    left: 0; right: 0; bottom: 0; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    padding: 6px max(8px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(8px, env(safe-area-inset-left, 0px));
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
    border-top: 1px solid var(--line);
  }
  .tabbar a {
    position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    font-size: 11px; color: var(--muted); font-weight: 500; text-decoration: none; height: 52px;
  }
  .tabbar a .ic { width: 22px; height: 22px; transition: transform .35s var(--ease-spring); }
  .tabbar a[aria-current="page"] { color: var(--accent); font-weight: 700; }
  .tabbar a[aria-current="page"] .ic { transform: translateY(-1px) scale(1.08); }
  .tab-ind {
    position: absolute; top: 0; left: 0; width: 56px; height: 32px; border-radius: 999px;
    background: var(--accent-tint); transition: transform .42s var(--ease-out);
  }
  .page-head { margin-bottom: 16px; }
  .page-title { font-size: 22px; }
  .stock-price { width: 100%; text-align: left; display: flex; align-items: baseline; gap: 4px 10px; flex-wrap: wrap; }
  .hide-phone { display: none !important; }
}
@media (min-width: 720px) { .show-phone { display: none !important; } }

/* =========================================================================
 * 格線與卡片
 * ========================================================================= */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 20px; }
.grid > * { min-width: 0; }
.s12 { grid-column: span 12; } .s8 { grid-column: span 8; } .s7 { grid-column: span 7; }
.s6 { grid-column: span 6; } .s5 { grid-column: span 5; } .s4 { grid-column: span 4; } .s3 { grid-column: span 3; }
@media (max-width: 1099px) {
  .s8, .s7, .s5 { grid-column: span 12; }
  .s4, .s3 { grid-column: span 6; }
  .t12 { grid-column: span 12; }
}
@media (max-width: 719px) {
  .grid { gap: 14px; }
  .s6, .s4, .s3 { grid-column: span 12; }
  .p6 { grid-column: span 6; }
}
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 20px; box-shadow: var(--shadow-sm); position: relative;
}
.card.flush { padding: 0; overflow: hidden; overflow: clip; }   /* clip 不會建立捲動容器，內部的 sticky 才能運作 */
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head > div:first-child { flex: 1 1 180px; min-width: 0; }
.card.flush .card-head { padding: 18px 20px 0; }
.card-title { font-size: 16px; font-weight: 700; line-height: 1.4; }
.card-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.card-foot { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-2); }
.card.flush .card-foot { margin: 0; padding: 12px 20px 16px; }
@media (max-width: 719px) {
  .card { padding: 16px; border-radius: 14px; }
  .card.flush .card-head { padding: 16px 16px 0; }
  .card.flush .card-foot { padding: 12px 16px 14px; }
}
.note { font-size: 13px; color: var(--ink-2); line-height: 1.65; }
.note.box { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; }

/* 數字指標 */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow-sm); }
.kpi-label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 24px; font-weight: 700; line-height: 1.25; margin-top: 4px; }
.kpi-sub { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
/* 指標的第二種算法（例如和永豐 App 相同的市值），比主要說明淡一階 */
.kpi-alt { color: var(--muted); margin-top: 2px; }
/* 英雄區總市值下方的市價（第二種算法） */
.hero-alt { color: var(--hero-muted); font-size: 12.5px; margin-top: 2px; }
@media (max-width: 719px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi-value { font-size: 20px; }
}
.stat-list { display: grid; gap: 0; }
.stat-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.stat-row:last-child { border-bottom: 0; }
.stat-row .k { color: var(--ink-2); }
.stat-row .v { font-weight: 600; text-align: right; }

/* =========================================================================
 * 控制項：按鈕、分段切換、篩選標籤、標記
 * ========================================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent;
  background: var(--hero); color: #fff; font-weight: 600; font-size: 14px; white-space: nowrap;
  transition: transform .15s var(--ease-out), background .2s, box-shadow .2s, border-color .2s;
}
.btn:hover { text-decoration: none; box-shadow: var(--shadow-md); }
.btn:active { transform: scale(.97); }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn.ghost:hover { border-color: var(--ink-2); box-shadow: none; }
.btn.quiet { background: transparent; color: var(--accent); padding: 0 8px; }
.btn.quiet:hover { background: var(--accent-tint); box-shadow: none; }
.btn.danger { background: var(--bad-ink); }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn[disabled] { opacity: .55; pointer-events: none; }
@media (pointer: coarse) { .btn { min-height: 44px; } .btn.sm { min-height: 40px; } }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; color: var(--ink-2);
  display: grid; place-items: center; transition: background .2s, transform .15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn:active { transform: scale(.94); }

.seg {
  position: relative; display: inline-flex; padding: 3px; gap: 2px; border-radius: 11px;
  background: var(--surface-2); border: 1px solid var(--line); max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg button, .seg a {
  position: relative; z-index: 1; border: 0; background: transparent; color: var(--ink-2);
  height: 32px; padding: 0 14px; border-radius: 8px; font-size: 13.5px; font-weight: 500; white-space: nowrap;
  transition: color .25s;
}
/* 頁內分頁（TabLinks）用連結：外觀和按鈕相同 */
.seg a { display: inline-flex; align-items: center; text-decoration: none; }
.seg a:hover { text-decoration: none; color: var(--ink); }
.seg button[aria-pressed="true"], .seg a[aria-current="page"] { color: var(--ink); font-weight: 700; }
.seg-ind {
  position: absolute; top: 3px; left: 0; height: 32px; border-radius: 8px; background: var(--surface);
  box-shadow: 0 1px 3px rgba(15, 27, 45, .12), 0 0 0 1px var(--line);
  transition: transform .38s var(--ease-out), width .38s var(--ease-out);
}
@media (pointer: coarse) { .seg button, .seg a, .seg-ind { height: 38px; } }
@media (max-width: 719px) { .seg button, .seg a { padding: 0 10px; } }   /* 手機上縮小左右留白，讓設定頁四個分頁不必捲動 */
.seg.on-dark { background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .12); }
.seg.on-dark button { color: var(--hero-muted); }
.seg.on-dark button[aria-pressed="true"] { color: var(--hero); }
.seg.on-dark .seg-ind { background: #fff; box-shadow: none; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2); font-size: 13.5px; font-weight: 500;
  transition: background .2s, color .2s, border-color .2s, transform .15s;
}
.chip:active { transform: scale(.96); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.chip .sw { width: 9px; height: 9px; border-radius: 3px; }
@media (pointer: coarse) { .chip { height: 40px; } }

.pill {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-3); color: var(--ink-2);
}
.pill .ic { width: 13px; height: 13px; stroke-width: 2.2; }
.pill.ok { background: var(--ok-tint); color: var(--ok-ink); }
.pill.warn { background: var(--warn-tint); color: var(--warn-ink); }
/* 可點的標記（例如逐筆明細的來源）：外觀維持標記，滑過時加外框提示可以修改 */
.src-edit { background: none; border: 0; padding: 0; border-radius: 999px; cursor: pointer; vertical-align: middle; }
.src-edit .pill { transition: box-shadow .2s; }
.src-edit:hover .pill { box-shadow: 0 0 0 1.5px var(--line-strong); }
.src-edit:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* 買進明細：幫家人代操的買進在來源下方標出家人 */
.owner-line { margin-top: 4px; }
/* 買進頁批次標註交易人：選取數量、選取按鈕、標註為…；窄畫面換行 */
.bulk-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 12px 20px 0; padding: 10px 12px; border-radius: 12px; background: var(--accent-tint); }
.bulk-count { font-size: 13.5px; margin-right: 4px; }
.bulk-apply { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.bulk-apply .dd { width: 160px; }
/* 批次標註的勾選框：不用瀏覽器預設樣式，外框、勾選色和已選的篩選按鈕一致（深淺色主題都跟著色票），勾號用 CSS 畫 */
.row-check {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none; cursor: pointer;
  width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid var(--line-strong); background: var(--surface);
  display: inline-grid; place-content: center; transition: background .15s, border-color .15s;
}
.row-check::after {
  content: ""; width: 5px; height: 10px; margin-top: -2px;
  border: solid var(--surface); border-width: 0 2px 2px 0; transform: rotate(45deg) scale(0); transition: transform .12s ease-out;
}
.row-check:hover { border-color: var(--ink-2); }
.row-check:checked { background: var(--ink); border-color: var(--ink); }
.row-check:checked::after { transform: rotate(45deg) scale(1); }
.row-check:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (pointer: coarse) { .row-check { width: 24px; height: 24px; } }
@media (prefers-reduced-motion: reduce) { .row-check, .row-check::after { transition: none; } }
.tbl tr.picked td { background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
@media (max-width: 640px) {
  .bulk-bar { margin: 12px 16px 0; }
  .bulk-apply { margin-left: 0; width: 100%; }
  .bulk-apply .dd { width: auto; flex: 1; }
}
.pill.bad { background: var(--bad-tint); color: var(--bad-ink); }
.pill.info { background: var(--accent-tint); color: var(--accent); }
.pill.brass { background: var(--brass-tint); color: var(--brass-ink); }
.pill.outline { background: transparent; box-shadow: inset 0 0 0 1px var(--line-strong); color: var(--ink-2); }
/*
 * 股票類別色：CategoryStyles 為每個類別產生 .cat-<代號> { --c: 類別色 }（深淺色主題各一個色階），
 * 色塊、長條直接用 --c；標記與代號徽章用 --c 混出淡底色與文字色（12% 底色、55% 文字，淺深色主題對比都在 5.9:1 以上）。
 * 未分類（類別代號空白）或類別已刪除時沒有 --c，一律用灰色；不設預設色會變成看不見但佔位置的空隙。
 */
.pill.cat { background: color-mix(in srgb, var(--c, var(--muted)) 12%, var(--surface)); color: color-mix(in srgb, var(--c, var(--muted)) 55%, var(--ink)); }
.pill.src-manual { background: var(--src-manual-tint); color: var(--src-manual-ink); }
/* 類別顏色選擇（系統 → 股票類別）：色塊依目前主題顯示淺色或深色色階 */
.cat-colors { display: flex; gap: 10px; flex-wrap: wrap; }
.cat-color { width: 40px; height: 40px; padding: 0; border-radius: 11px; border: 2px solid transparent; background: var(--surface-2); display: grid; place-items: center; cursor: pointer; }
.cat-color-dot { width: 24px; height: 24px; border-radius: 7px; background: var(--c-light); }
.cat-color[aria-checked="true"], .cat-color.on { border-color: var(--ink); }
.cat-color:disabled { opacity: .3; cursor: not-allowed; }
.cat-color:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .cat-color-dot { background: var(--c-dark); } }
:root[data-theme="dark"] .cat-color-dot { background: var(--c-dark); }
/* 自訂顏色：彩虹框表示可以選任何顏色，透明的 input 蓋在上面接收點擊 */
.cat-custom { position: relative; overflow: hidden; background: conic-gradient(#e8505b, #f2c46b, #4cc38a, #2990e8, #c278c9, #e8505b); }
.cat-custom input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.cat-custom .cat-color-dot { box-shadow: 0 0 0 2px var(--surface); pointer-events: none; }
.cat-custom:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.cat-preview { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.cat-warn { display: flex; gap: 6px; align-items: flex-start; margin-top: 6px; font-size: 12.5px; color: var(--warn-ink); }
.cat-warn .ic { flex: none; margin-top: 2px; }
.sw { background: var(--c, var(--muted)); }

/* 股票代號徽章 */
.tick { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tick-code {
  font-family: var(--font-num); font-weight: 800; font-size: 13px; letter-spacing: 0;
  min-width: 52px; height: 30px; padding: 0 8px; border-radius: 8px; display: grid; place-items: center; flex: none;
}
.tick-code { background: color-mix(in srgb, var(--c, var(--muted)) 12%, var(--surface)); color: color-mix(in srgb, var(--c, var(--muted)) 55%, var(--ink)); }
.tick-name { font-size: 14px; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tick-meta { font-size: 12px; color: var(--muted); }

/* 進度條 */
.meter { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; position: relative; }
.meter > i {
  position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: var(--accent);
  width: var(--w, 0%); transform-origin: left; animation: meterIn 1s var(--ease-out) .25s both;
}
.meter.brass > i { background: var(--brass); }
.meter > i.soft { background: var(--brass-soft); }   /* 預計（淺色），要放在實心之前 */

/* 表單 */
.field { display: grid; gap: 6px; }
.field label { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.field .seg { justify-self: start; }
.input, .select {
  height: 42px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--surface);
  padding: 0 12px; font-size: 14.5px; width: 100%; transition: border-color .2s, box-shadow .2s;
}
.input:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.select { appearance: none; padding-right: 36px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 18px, calc(100% - 13px) 18px; background-size: 5px 5px; background-repeat: no-repeat; }
/* 開關：label 預設是行內元素，必須設成 inline-block 才有寬高（放在表格裡才不會跑版） */
.switch { position: relative; display: inline-block; vertical-align: middle; width: 44px; height: 26px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--switch-off); transition: background .25s; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .3s var(--ease-spring); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:hover + span { filter: brightness(1.08); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.tbl td.c, .tbl th.c { text-align: center; }
/* 交易頁「賣出」：展開的對應買進（一筆一行，可換行；捲動時跟著表格走，不凍結第一欄） */
.tbl tr.sale-buys-row td { background: var(--surface-2); white-space: normal; padding-top: 8px; padding-bottom: 10px; }
.sale-buys { margin: 0; padding-left: 18px; display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); line-height: 1.6; }

/* =========================================================================
 * 自訂下拉選單
 * ========================================================================= */
.dd { position: relative; width: 100%; }
.dd-native { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.dd-btn {
  width: 100%; min-height: 42px; display: flex; align-items: center; gap: 10px; text-align: left;
  border-radius: 10px; border: 1px solid var(--line-strong); background: var(--surface); padding: 0 12px; font-size: 14.5px; color: var(--ink);
  transition: border-color .2s, box-shadow .2s;
}
.dd-btn:hover { border-color: var(--ink-2); }
.dd-btn:focus-visible, .dd-btn.open { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.dd-val { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; overflow: hidden; }
.dd-val .dd-text, .dd-val .dd-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-chev { color: var(--muted); transition: transform .25s var(--ease-out); }
.dd-btn.open .dd-chev { transform: rotate(180deg); }
.dd .tick-code, .dd-pop .tick-code { height: 24px; min-width: 60px; font-size: 12px; border-radius: 7px; }
.filter-bar .dd { min-width: 230px; }
/* 交易頁篩選：期間分段＋指定年度下拉並排（窄時換行）；年度與類別的下拉不用那麼寬 */
.period-pick { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.period-pick .dd, .filter-bar .period-pick .dd { min-width: 0; width: 132px; }
.filter-bar .cat-pick .dd { min-width: 170px; }
.dd-pop {
  position: fixed; z-index: 95; overflow-y: auto; overscroll-behavior: contain; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg);
  transform-origin: top center; animation: ddIn .16s var(--ease-out) both;
}
.dd-pop.up { transform-origin: bottom center; }
.dd-pop.out { animation: ddOut .12s ease forwards; }
.dd-opt {
  display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 8px 10px; border-radius: 8px; cursor: pointer;
  font-size: 14.5px; color: var(--ink); transition: background .12s;
}
@media (pointer: coarse) { .dd-opt { min-height: 46px; } .dd-btn { min-height: 46px; } }
.dd-opt.active { background: var(--surface-2); }
.dd-opt[aria-selected="true"] { font-weight: 700; }
.dd-opt .dd-text { flex: 1; min-width: 0; display: grid; line-height: 1.35; }
.dd-note { font-size: 12px; color: var(--muted); font-weight: 400; }
.dd-check { color: var(--accent); opacity: 0; transform: scale(.6); transition: opacity .15s, transform .2s var(--ease-spring); }
.dd-opt[aria-selected="true"] .dd-check { opacity: 1; transform: none; }
@keyframes ddIn { from { opacity: 0; transform: translateY(-4px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes ddOut { to { opacity: 0; transform: translateY(-2px) scale(.98); } }
.dd-pop.up { animation-name: ddInUp; }
@keyframes ddInUp { from { opacity: 0; transform: translateY(4px) scale(.97); } to { opacity: 1; transform: none; } }

/* =========================================================================
 * 表格：手機凍結第一欄與表頭，可左右滑動
 * ========================================================================= */
.tbl-shell { position: relative; }
.tbl-wrap { overflow: auto; max-height: var(--tbl-max, none); overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; }
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; min-width: var(--tbl-min, 0); font-size: 14px; }
.tbl th, .tbl td { padding: 11px 14px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); background: var(--surface); }
.tbl th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2); color: var(--muted);
  font-size: 12.5px; font-weight: 600; height: 40px; padding-top: 0; padding-bottom: 0;
}
.tbl th.r, .tbl td.r { text-align: right; }
.tbl td.num, .tbl td .num { font-size: 14px; }
.tbl tbody tr { transition: background .2s; }
.tbl tbody tr.link { cursor: pointer; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl tfoot td { font-weight: 700; background: var(--surface-2); border-bottom: 0; position: sticky; bottom: 0; z-index: 1; }
.tbl .sticky { position: sticky; left: 0; z-index: 1; }
.tbl th.sticky { z-index: 3; }
.tbl tfoot td.sticky { z-index: 2; }
/* 捲動後在凍結欄右側加陰影，提示後面還有欄位 */
.tbl .sticky::after {
  content: ''; position: absolute; top: 0; bottom: -1px; right: -14px; width: 14px; pointer-events: none;
  background: linear-gradient(to right, rgba(15, 27, 45, .10), transparent); opacity: 0; transition: opacity .25s;
}
.tbl-wrap.scrolled .sticky::after { opacity: 1; }
.tbl-shell::after {
  content: ''; position: absolute; top: 0; right: 0; bottom: 0; width: 28px; pointer-events: none; border-radius: 0 0 16px 0;
  background: linear-gradient(to left, var(--surface), transparent); opacity: 0; transition: opacity .25s;
}
.tbl-shell.more::after { opacity: 1; }
.tbl th button.sort {
  border: 0; background: none; padding: 0; color: inherit; font: inherit; display: inline-flex; align-items: center; gap: 4px; height: 40px;
}
.tbl th[aria-sort] button.sort { color: var(--ink); }
.tbl th .arr { width: 12px; height: 12px; opacity: .35; transition: transform .25s, opacity .2s; }
.tbl th[aria-sort] .arr { opacity: 1; }
.tbl th[aria-sort="ascending"] .arr { transform: rotate(180deg); }
.swipe-hint { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); padding: 8px 16px 0; }
.swipe-hint[hidden] { display: none; }
/* 滑鼠可以按住拖曳捲動（觸控裝置本來就能滑） */
.tbl-wrap.can-drag { cursor: grab; }
.tbl-wrap.dragging { cursor: grabbing; user-select: none; -webkit-user-select: none; }
.tbl-wrap.dragging * { cursor: grabbing !important; }
.tbl-wrap.dragging tbody tr:hover td { background: var(--surface); }
@media (max-width: 719px) {
  .tbl th, .tbl td { padding: 10px 12px; }
  .tbl .sticky { max-width: 148px; }
  .tbl .sticky .tick-name { max-width: 84px; }
  /* 凍結欄很窄：代號徽章和名稱放第一行，說明（日期、類別…）獨立一行用滿整欄寬，
     不然「2026/05/12 賣出」這類較長的說明會超出凍結欄（行數和原本相同） */
  .tbl .sticky .tick { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 8px; row-gap: 2px; align-items: center; }
  .tbl .sticky .tick > div { display: contents; }
  .tbl .sticky .tick-meta { grid-column: 1 / -1; }
}
.row-flash td { animation: rowFlash 1.6s var(--ease-out); }

/* =========================================================================
 * 總覽英雄區
 * ========================================================================= */
.hero {
  grid-column: span 12; position: relative; overflow: hidden; isolation: isolate;
  border-radius: 22px; padding: 26px 28px 22px; color: var(--hero-ink);
  background:
    radial-gradient(120% 140% at 100% 0%, var(--hero-2) 0%, transparent 55%),
    var(--hero);
  display: grid; grid-template-columns: minmax(260px, 5fr) 7fr; gap: 28px; align-items: stretch;
}
.hero-label { color: var(--hero-muted); font-size: 14px; display: flex; align-items: center; gap: 8px; }
.hero-value { font-size: clamp(36px, 5.2vw, 56px); font-weight: 800; line-height: 1.08; margin-top: 6px; letter-spacing: -.02em; }
.hero-value small { font-size: .42em; font-weight: 600; color: var(--hero-muted); margin-right: 6px; letter-spacing: 0; }
.hero-change { margin-top: 10px; display: inline-flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; }
.hero-change .badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; background: rgba(255, 140, 155, .14); color: var(--hero-gain); }
.hero-change .badge.down { background: rgba(111, 224, 166, .14); color: var(--hero-loss); }
.hero-change .muted { color: var(--hero-muted); font-weight: 400; font-size: 13px; }
.hero-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; margin-top: 22px; padding-top: 18px; border-top: 1px solid rgba(255, 255, 255, .12); }
.hero-stat .k { color: var(--hero-muted); font-size: 12.5px; }
.hero-stat .v { font-size: 19px; font-weight: 700; margin-top: 2px; }
.hero-stat .s { color: var(--hero-muted); font-size: 12px; }
.hero-chart { display: flex; flex-direction: column; min-width: 0; }
.hero-chart-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.legend-inline { display: flex; gap: 14px; font-size: 12.5px; color: var(--hero-muted); }
.legend-inline span { display: inline-flex; align-items: center; gap: 6px; }
.legend-inline i { width: 14px; height: 0; border-top: 2px solid #fff; display: inline-block; }
.legend-inline i.dash { border-top: 2px dashed var(--hero-muted); }
@media (max-width: 1099px) { .hero { grid-template-columns: 1fr; gap: 18px; } .hero-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 719px) {
  .hero { padding: 20px 18px 16px; border-radius: 18px; }
  .hero-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 18px; padding-top: 14px; }
  .hero-stat .v { font-size: 17px; }
}

/* =========================================================================
 * 圖表
 * ========================================================================= */
.chart { position: relative; width: 100%; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; font-family: var(--font-num); }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .crosshair { stroke: var(--line-strong); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0; transition: opacity .15s; }
.chart.on-dark .gridline { stroke: rgba(255, 255, 255, .08); }
.chart.on-dark .axis-label { fill: var(--hero-muted); }
.chart.on-dark .crosshair { stroke: rgba(255, 255, 255, .35); }
.line-draw { stroke-dasharray: var(--len); stroke-dashoffset: var(--len); animation: draw 1.3s var(--ease-out) forwards; animation-delay: var(--d, 0s); }
.area-fade { opacity: 0; animation: fadeIn .9s ease forwards; animation-delay: var(--d, .5s); }
.pt { transition: r .15s, opacity .2s; }
.pt-pop { opacity: 0; transform-box: fill-box; transform-origin: center; animation: pop .45s var(--ease-spring) forwards; animation-delay: var(--d, 1s); }
/* 重畫（例如旋轉螢幕）時不重播進場動畫 */
.chart.static .line-draw, .chart.static .area-fade, .chart.static .pt-pop { animation: none; opacity: 1; stroke-dashoffset: 0; }
.chart.static .pulse-ring { display: none; }
.pulse-ring { transform-box: fill-box; transform-origin: center; animation: pulseRing 2s var(--ease-out) 1.4s 2; opacity: 0; }

/* 長條：由底部長出，依序延遲 */
.bars { display: flex; align-items: flex-end; gap: var(--bar-gap, 10px); height: var(--plot-h, 180px); position: relative; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; position: relative; min-width: 0; cursor: default; }
.bar-stack { width: 100%; max-width: 34px; display: flex; flex-direction: column-reverse; gap: 2px; transform-origin: bottom; transform: scaleY(0); animation: grow .7s var(--ease-out) forwards; animation-delay: calc(var(--i, 0) * 40ms + .15s); }
.bar-seg { width: 100%; }
.bar-seg:last-child { border-radius: 4px 4px 0 0; }
.bar-seg.plan { background: transparent; border: 1.5px dashed var(--line-strong); border-bottom: 0; border-radius: 4px 4px 0 0; }
.bar-seg.est { background: repeating-linear-gradient(135deg, var(--brass-soft) 0 4px, transparent 4px 7px); box-shadow: inset 0 0 0 1px var(--brass-soft); }
.bar-label { position: absolute; font-size: 11px; color: var(--ink-2); font-family: var(--font-num); font-weight: 700; white-space: nowrap; transform: translateY(-4px); opacity: 0; animation: fadeIn .4s ease forwards; animation-delay: calc(var(--i, 0) * 40ms + .7s); }
.bar-x { display: flex; gap: var(--bar-gap, 10px); margin-top: 8px; }
.bar-x span { flex: 1; text-align: center; font-size: 11.5px; color: var(--muted); min-width: 0; }
.bar-col:hover .bar-stack, .bar-col.active .bar-stack { filter: brightness(1.06); }
.bar-col.dim .bar-stack { opacity: .45; }
/* 格線只畫在柱子的高度內（不含下方的月份標籤），刻度才會和柱子的高度對齊；有負值時 0 的格線就是柱子的基準線 */
.plot-grid { position: absolute; inset: 0 0 auto 0; height: var(--plot-h, 180px); display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.plot-grid div { border-top: 1px solid var(--grid); position: relative; }
.plot-grid div span { position: absolute; right: 100%; top: -8px; padding-right: 8px; white-space: nowrap; font-size: 11px; color: var(--muted); font-family: var(--font-num); }
.plot { position: relative; margin-left: 40px; }
/* 有負值的直條圖（app.js drawBars）：柱子分成 0 基準線以上、以下兩半，負的柱子從基準線往下長 */
.bar-half { width: 100%; flex: none; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.bar-half.down { justify-content: flex-start; }
.bar-stack.neg { flex-direction: column; transform-origin: top; }
.bar-stack.neg .bar-seg:last-child { border-radius: 0 0 4px 4px; }
.bar-label.below { transform: none; }
.plot-grid div.zero { border-top-color: var(--line-strong); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend i.dash { background: transparent; border: 1.5px dashed var(--line-strong); }
.legend i.est { background: repeating-linear-gradient(135deg, var(--brass-soft) 0 3px, transparent 3px 5px); box-shadow: inset 0 0 0 1px var(--brass-soft); }

/* 橫向長條 */
.hbar-list { display: grid; gap: 14px; }
.hbar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; }
.hbar-row .note.nowrap { overflow: hidden; text-overflow: ellipsis; }
.hbar-track { grid-column: 1 / -1; height: 10px; border-radius: 999px; background: var(--surface-3); overflow: hidden; display: flex; gap: 2px; }
.hbar-fill { height: 100%; border-radius: 999px; width: var(--w); background: var(--c, var(--muted)); transform-origin: left; transform: scaleX(0); animation: growX .9s var(--ease-out) forwards; animation-delay: calc(var(--i, 0) * 60ms + .1s); }
.hbar-fill.brass { background: var(--brass); } .hbar-fill.brass-soft { background: var(--brass-soft); }
.hbar-fill.src-dca { background: var(--src-dca); } .hbar-fill.src-drip { background: var(--brass); } .hbar-fill.src-manual { background: var(--src-manual); }

/* 甜甜圈 */
.donut-wrap { display: grid; grid-template-columns: 168px 1fr; gap: 20px; align-items: center; }
.donut { position: relative; width: 168px; height: 168px; }
.donut svg { transform: rotate(-90deg); }
.donut circle.seg-arc { fill: none; stroke-width: 18; stroke-linecap: butt; transition: stroke-dashoffset 1.1s var(--ease-out), stroke-width .2s; }
.donut circle.seg-arc:hover { stroke-width: 22; }
.donut-center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.donut-center b { font-family: var(--font-num); font-size: 26px; display: block; line-height: 1.1; }
.donut-center span { font-size: 12px; color: var(--muted); }
@media (max-width: 1099px) and (min-width: 720px) { .donut-wrap { grid-template-columns: 140px 1fr; } .donut { width: 140px; height: 140px; } }
@media (max-width: 380px) { .donut-wrap { grid-template-columns: 1fr; justify-items: center; } }

/* 圖表提示框 */
.tip {
  position: absolute; z-index: 20; pointer-events: none; min-width: 150px; max-width: 240px;
  background: var(--ink); color: var(--surface); border-radius: 10px; padding: 9px 12px; font-size: 12.5px; line-height: 1.5;
  box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(4px) scale(.98); transition: opacity .14s, transform .14s;
}
:root[data-theme="dark"] .tip { background: #E9EEF6; color: #0F1B2D; }
.tip.show { opacity: 1; transform: none; }
.tip b { font-family: var(--font-num); }
.tip .row { display: flex; justify-content: space-between; gap: 14px; }
.tip .row i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.tip .t { font-weight: 700; margin-bottom: 2px; }

/* =========================================================================
 * 清單：提醒、時間軸、事件
 * ========================================================================= */
.alerts { display: grid; gap: 4px; }
.alert { display: grid; grid-template-columns: 36px 1fr; gap: 12px; padding: 12px; border-radius: 12px; transition: background .2s; }
.alert:hover { background: var(--surface-2); }
.alert-ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; }
.alert-ic.brass { background: var(--brass-tint); color: var(--brass-ink); }
.alert-ic.ok { background: var(--ok-tint); color: var(--ok-ink); }
.alert-ic.info { background: var(--accent-tint); color: var(--accent); }
.alert-ic.warn { background: var(--warn-tint); color: var(--warn-ink); }
.alert-ic.bad { background: var(--bad-tint); color: var(--bad-ink); }
.alert-title { font-weight: 700; font-size: 14.5px; line-height: 1.45; }
.alert-body { font-size: 13px; color: var(--ink-2); margin-top: 2px; line-height: 1.6; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; }
.tl-item { display: grid; grid-template-columns: 52px 1fr auto; gap: 14px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.tl-item:last-child { border-bottom: 0; }
.tl-date { text-align: center; border-radius: 12px; padding: 6px 0; background: var(--surface-2); line-height: 1.15; }
.tl-date b { display: block; font-family: var(--font-num); font-size: 19px; }
.tl-date span { font-size: 11px; color: var(--muted); }
.tl-date.brass { background: var(--brass-tint); color: var(--brass-ink); }
.tl-date.brass span { color: var(--brass-ink); }
.tl-title { font-weight: 700; font-size: 14.5px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tl-detail { font-size: 12.5px; color: var(--muted); }
.tl-amt { text-align: right; }
.tl-amt b { font-family: var(--font-num); font-size: 16px; display: block; }
.tl-amt span { font-size: 11.5px; color: var(--muted); }
@media (max-width: 719px) { .tl-item { grid-template-columns: 46px 1fr; } .tl-amt { grid-column: 2; text-align: left; display: flex; gap: 8px; align-items: baseline; } .tl-amt b { display: inline; font-size: 15px; } }

/* 股息月曆（12 個月） */
.months { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; align-items: end; height: 64px; }
.months .m { display: flex; flex-direction: column; justify-content: flex-end; height: 100%; gap: 2px; position: relative; }
.months .m i { display: block; border-radius: 3px 3px 1px 1px; background: var(--brass); transform-origin: bottom; transform: scaleY(0); animation: grow .6s var(--ease-out) forwards; animation-delay: calc(var(--i) * 45ms + .3s); }
.months .m i.soft { background: var(--brass-soft); }
.months .m i.est { background: repeating-linear-gradient(135deg, var(--brass-soft) 0 3px, transparent 3px 5px); box-shadow: inset 0 0 0 1px var(--brass-soft); }
.months .m i.zero { height: 3px; background: var(--surface-3); }
.months-x { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; margin-top: 6px; }
.months-x span { font-size: 10.5px; color: var(--muted); text-align: center; font-family: var(--font-num); }
.months-x span.now { color: var(--ink); font-weight: 800; }

/* 目標環 */
.ring { position: relative; width: 112px; height: 112px; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; }
.ring .track { stroke: var(--surface-3); }
.ring .val { stroke: var(--brass); stroke-linecap: round; transition: stroke-dashoffset 1.3s var(--ease-out); }
.ring .val2 { stroke: var(--brass-soft); transition: stroke-dashoffset 1.3s var(--ease-out); }
.ring-center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: 1.15; }
.ring-center b { font-family: var(--font-num); font-size: 22px; }
.ring-center span { font-size: 11px; color: var(--muted); display: block; }

/* =========================================================================
 * AI 助理
 * ========================================================================= */
.chat-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
@media (max-width: 1099px) { .chat-layout { grid-template-columns: minmax(0, 1fr); } }   /* minmax(0) 避免不換行的查詢紀錄或表格撐寬頁面 */
.chat { display: flex; flex-direction: column; min-height: min(72vh, 760px); }
.chat-log { flex: 1; display: flex; flex-direction: column; gap: 18px; padding: 20px; overflow-y: auto; max-height: min(64vh, 680px); scroll-behavior: smooth; }
/* 手機：對話跟著整頁捲動，輸入框固定在下方分頁列上面 */
@media (max-width: 719px) {
  /* 對話區至少和上方列到下方分頁列之間的可視高度一樣高（只有開場白時也不會縮成一小塊），用量等資訊往下捲才看到 */
  .chat {
    min-height: calc(100vh - 56px - var(--tabbar-h) - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    min-height: calc(100dvh - 56px - var(--tabbar-h) - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }
  .chat-log { max-height: none; overflow: visible; padding: 16px; }
  .msg { scroll-margin-bottom: calc(var(--tabbar-h) + 180px); }   /* 捲到最新訊息時，不被固定的輸入框擋住 */
  .composer { position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px)); z-index: 5; background: var(--surface); border-radius: 0 0 14px 14px; box-shadow: 0 -8px 16px -12px rgba(15, 27, 45, .25); }
}
.msg { display: flex; gap: 12px; max-width: 760px; animation: rise .4s var(--ease-out) backwards; }
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.msg-ava { width: 32px; height: 32px; border-radius: 10px; flex: none; display: grid; place-items: center; background: var(--hero); color: var(--hero-brass); }
.msg.me .msg-ava { background: var(--accent-tint); color: var(--accent); border-radius: 50%; font-size: 13px; font-weight: 700; }
.bubble { background: var(--surface-2); border-radius: 4px 14px 14px 14px; padding: 12px 14px; font-size: 14.5px; line-height: 1.75; min-width: 0; }
.msg.me .bubble { background: var(--hero); color: #fff; border-radius: 14px 4px 14px 14px; }
.bubble b.num { font-size: 15.5px; }
/* AI 回答（SafeMarkdown 產生的段落、清單、表格） */
.ans p { margin: 0 0 8px; } .ans p:last-child { margin-bottom: 0; }
.ans ul, .ans ol { margin: 4px 0 8px; padding-left: 22px; } .ans li { margin: 2px 0; }
.ans code { font-family: var(--font-num); background: var(--surface-3); padding: 1px 5px; border-radius: 5px; font-size: .92em; }
.md-table { overflow-x: auto; margin: 6px 0 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.md-table table { border-collapse: collapse; width: 100%; font-size: 13px; line-height: 1.5; }
.md-table th, .md-table td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.md-table th { color: var(--muted); font-weight: 600; background: var(--surface-2); }
.md-table tr:last-child td { border-bottom: 0; }
.md-table .r { text-align: right; font-family: var(--font-num); } .md-table .c { text-align: center; }
.chat-notice { display: flex; gap: 8px; align-items: flex-start; margin-top: 10px; padding: 8px 10px; border-radius: 10px; background: var(--warn-tint); color: var(--warn-ink); font-size: 12.5px; line-height: 1.6; }
.chat-notice .ic { flex: none; margin-top: 3px; }
.ans-foot { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.ans-foot .meta { font-size: 11.5px; color: var(--muted); font-family: var(--font-num); margin-left: auto; }
.tool-trace { margin-bottom: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); overflow: hidden; }
.tool-trace summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 8px 10px; font-size: 12.5px; color: var(--ink-2); }
.tool-trace summary::-webkit-details-marker { display: none; }
.tool-trace summary .chev { margin-left: auto; transition: transform .25s; }
.tool-trace[open] summary .chev { transform: rotate(180deg); }
.tool-step { display: flex; gap: 8px; align-items: center; padding: 7px 10px; border-top: 1px dashed var(--line); font-size: 12px; color: var(--muted); font-family: var(--font-num); overflow-x: auto; white-space: nowrap; }
.tool-step .ic { width: 14px; height: 14px; }
.spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
.mini-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-top: 10px; }
.mini-kpis div { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; animation: rise .4s var(--ease-out) backwards; animation-delay: calc(var(--i) * 60ms); }
.mini-kpis span { font-size: 11.5px; color: var(--muted); display: block; }
.mini-kpis b { font-family: var(--font-num); font-size: 16px; }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
.caret::after { content: ''; display: inline-block; width: 2px; height: 1em; background: var(--accent); margin-left: 2px; vertical-align: -2px; animation: blink .9s steps(1) infinite; }
.composer { border-top: 1px solid var(--line); padding: 12px; display: grid; gap: 10px; }
.suggest { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.suggest::-webkit-scrollbar { display: none; }
.suggest .chip { flex: none; }
/* 用滑鼠操作時換行全部顯示：一列左右滑是給觸控用的，捲軸隱藏後滑鼠捲不到右邊被遮住的建議 */
@media (hover: hover) and (pointer: fine) { .suggest { flex-wrap: wrap; overflow-x: visible; } }
.input-row { display: flex; gap: 8px; align-items: flex-end; }
.input-row textarea { flex: 1; resize: none; min-height: 44px; max-height: 140px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface); padding: 11px 14px; font-size: 15px; line-height: 1.5; }
.input-row textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.send { width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--hero); color: #fff; display: grid; place-items: center; transition: transform .15s, opacity .2s; }
.send:active { transform: scale(.94); }
.send[disabled] { opacity: .4; }
.model-chip { display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); font-size: 13px; font-weight: 600; color: var(--ink); }
.model-chip .dot { width: 7px; height: 7px; }
.tools-list { display: grid; gap: 2px; }
.tool-row { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.tool-row:last-child { border-bottom: 0; }
/* 系統頁「通知開關」：每種通知一列，右邊是各管道的開關；手機寬度時說明文字換到下一行 */
.notify-grid { display: grid; }
.notify-row { display: grid; grid-template-columns: minmax(0, 1fr) repeat(2, 84px); gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.notify-row:last-child { border-bottom: 0; }
.notify-head { padding-top: 0; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.notify-row b { font-size: 14px; }
.notify-detail { display: block; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.notify-req { margin-left: 6px; height: 20px; font-size: 11.5px; }
.notify-ch { display: flex; justify-content: center; }
/* 測試發送列：和上面的開關列用虛線分開 */
.notify-test { margin-top: 4px; border-top: 1px dashed var(--line-strong); border-bottom: 0; }
.notify-test .btn { min-width: 64px; justify-content: center; }
@media (max-width: 640px) { .notify-row { grid-template-columns: minmax(0, 1fr) repeat(2, 64px); gap: 8px; } }
/* 到期清單：狀態與按鈕靠右；手機寬度時換到名稱與說明下方，說明文字不被擠壓 */
.expiry-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; flex: none; }
.tool-row .expiry-actions .pill { margin-left: 0; }
@media (max-width: 640px) {
  .expiry-row { flex-wrap: wrap; }
  .expiry-actions { margin-left: 0; width: 100%; }
}
.tool-row b { font-size: 14px; display: block; }
.tool-row span { font-size: 12.5px; color: var(--muted); }
.tool-row .pill { margin-left: auto; flex: none; }
/* 系統頁「股票資料」：配息頻率與股息再投入標記靠右；手機寬度時換到名稱下方（不擠壓股票名稱）。
   手機改用格線：代號徽章 | 名稱 | 修改，第二行的標記從名稱那一欄開始，徽章寬度不同也對齊 */
.stock-tags { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; margin-left: auto; }
.tool-row .stock-tags .pill { margin-left: 0; }
@media (max-width: 640px) {
  .stock-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; column-gap: 10px; row-gap: 6px; }
  .stock-row .tick { display: contents; }
  .stock-row .stock-tags { grid-column: 2 / 4; grid-row: 2; justify-content: flex-start; margin-left: 0; }
}

/* 和大盤比較 */
.bench { display: grid; grid-template-columns: minmax(260px, 4fr) 8fr; gap: 28px; align-items: start; }
@media (max-width: 1099px) { .bench { grid-template-columns: 1fr; gap: 18px; } }
.bench-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.bench-row.mine .bench-v { font-size: 26px; }
.bench-k { font-weight: 700; font-size: 14.5px; display: grid; }
.bench-k span { font-weight: 400; font-size: 12.5px; color: var(--muted); }
.bench-v { font-size: 22px; font-weight: 800; text-align: right; align-self: center; }
.bench-s { grid-column: 1 / -1; font-size: 12.5px; color: var(--ink-2); }
.bench-diff { margin-top: 12px; display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: 12px; font-size: 13.5px; line-height: 1.6; }
.bench-diff .ic { margin-top: 3px; }
.bench-diff.ahead { background: var(--bad-tint); color: var(--gain); }
.bench-diff.behind { background: var(--ok-tint); color: var(--loss); }
.bench-chart-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* AI 總開關與停用狀態 */
.ai-master { display: flex; align-items: center; gap: 14px; }
.switch-lg { width: 52px; height: 30px; }
.switch-lg span::after { width: 24px; height: 24px; }
.switch-lg input:checked + span::after { transform: translateX(22px); }
fieldset.ai-fields { border: 0; padding: 0; margin: 0; min-width: 0; transition: opacity .25s; }
fieldset.ai-fields:disabled { opacity: .45; }
.ai-off { text-align: center; max-width: 620px; margin: 24px auto 0; padding: 36px 24px; }
.ai-off-ic { width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 16px; display: grid; place-items: center; background: var(--surface-3); color: var(--muted); }
.ai-off-ic .ic { width: 30px; height: 30px; }
.ai-off h2 { font-size: 20px; }
.ai-off p { color: var(--ink-2); margin-top: 8px; font-size: 14.5px; }
.nav a.off .ic, .tabbar a.off .ic { opacity: .45; }
.nav-badge { margin-left: auto; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--warn-tint); color: var(--warn-ink); }
@media (max-width: 1099px) { .nav .nav-badge { margin: 0; } }
.tabbar .nav-badge { position: absolute; top: 2px; right: calc(50% - 30px); padding: 0 5px; font-size: 9.5px; line-height: 15px; }

/* =========================================================================
 * 登入頁：深藍底＋淡淡的帳本橫線，置中一欄；唯一的動態是一疊逐枚落下的硬幣
 * ========================================================================= */
.login {
  position: relative; overflow: hidden; min-height: 100dvh; display: grid; place-items: center; background: var(--hero); color: var(--hero-ink);
  padding: calc(32px + env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-right, 0px)) calc(32px + env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px));
}
/* 帳本橫線：越往下越明顯，像一本攤開的帳簿 */
.login::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(to bottom, transparent 0 43px, rgba(255, 255, 255, .06) 43px 44px);
  -webkit-mask-image: linear-gradient(to bottom, transparent 10%, #000 90%); mask-image: linear-gradient(to bottom, transparent 10%, #000 90%);
}
.login-inner { position: relative; width: 100%; max-width: 380px; display: grid; justify-items: center; gap: 28px; }
.login-brand { display: grid; justify-items: center; gap: 12px; }
.login-brand h1 { font-size: 22px; font-weight: 700; letter-spacing: .02em; }   /* 名稱是英文（Stock ledger），字距不用像中文那麼寬 */
.coin-stack { width: 76px; height: 80px; overflow: visible; }
.coin { animation: coinDrop .5s var(--ease-out) both; animation-delay: calc(var(--i) * 110ms + .15s); }
.coin-face { fill: var(--hero-brass); stroke: rgba(255, 255, 255, .55); stroke-width: 1; }
.coin-side { fill: #B88633; }
@keyframes coinDrop { from { opacity: 0; transform: translateY(-26px); } to { opacity: 1; transform: none; } }
.login-card {
  width: 100%; background: var(--surface); color: var(--ink); border-radius: 18px; padding: 28px 24px 18px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .08) inset, 0 24px 60px rgba(0, 0, 0, .35); animation: rise .6s var(--ease-out) .35s backwards;
}
.login-card h2 { font-size: 20px; }
.login-card p { color: var(--ink-2); margin-top: 4px; font-size: 14px; }
.login-alert { margin-top: 14px; }
.login-alert.bad { color: var(--bad-ink); background: var(--bad-tint); }
.gbtn {
  margin-top: 22px; width: 100%; height: 50px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface);
  display: flex; align-items: center; justify-content: center; gap: 12px; font-weight: 600; font-size: 15px; color: var(--ink);
  transition: box-shadow .2s, transform .15s, border-color .2s;
}
.gbtn:hover { box-shadow: var(--shadow-md); border-color: var(--ink-2); text-decoration: none; }
.gbtn:active { transform: scale(.98); }
.gbtn.loading .glogo { display: none; }
/* 安全說明清單（AI 助理頁「安全邊界」） */
.secure-list { display: grid; gap: 10px; }
.secure-list div { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; color: var(--ink-2); }
.secure-list .ic { color: var(--ok-ink); margin-top: 2px; }
.login-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px 20px; margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 13px; }

/* =========================================================================
 * 公開頁面（關於本網站、隱私權政策）：不需要登入，閱讀用的單欄版面
 * ========================================================================= */
.pub { min-height: 100dvh; display: flex; flex-direction: column; background: var(--surface); color: var(--ink); }
.pub-top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line);
  padding: calc(14px + env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-right, 0px)) 14px max(20px, env(safe-area-inset-left, 0px));
}
.pub-top .brand { padding: 0; }
.pub-top .brand:hover { text-decoration: none; }
.pub-main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 40px 20px 56px; }
.pub-hero h1, .pub-doc h1 { font-size: clamp(26px, 4vw, 36px); line-height: 1.3; }
.pub-hero .lead { margin-top: 14px; font-size: 16px; color: var(--ink-2); line-height: 1.8; max-width: 36em; }
.pub-section { margin-top: 40px; }
.pub-section h2, .pub-doc h2 { font-size: 19px; }
.pub-doc h2 { margin-top: 32px; }
.pub-section p, .pub-doc p { margin-top: 10px; color: var(--ink-2); line-height: 1.8; }
.pub-doc .pub-meta { font-size: 13px; color: var(--muted); }
.pub-list, .pub-doc ul { margin: 10px 0 0; padding-left: 1.3em; color: var(--ink-2); line-height: 1.8; display: grid; gap: 4px; }
.pub-features { list-style: none; padding: 0; margin: 16px 0 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 28px; }
.pub-features li { display: flex; gap: 12px; align-items: flex-start; }
.pub-features h3 { font-size: 15px; }
.pub-features p { margin-top: 4px; font-size: 14px; line-height: 1.7; }
.pub-ic { width: 36px; height: 36px; border-radius: 10px; background: var(--hero); color: var(--hero-brass); display: grid; place-items: center; flex: none; }
.pub-foot { border-top: 1px solid var(--line); padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px)); text-align: center; font-size: 13px; color: var(--muted); }
.pub-foot nav { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px 20px; }
.pub-foot p { margin: 10px 0 0; }
@media (max-width: 599px) {
  .pub-main { padding-top: 28px; }
  .pub-features { grid-template-columns: 1fr; }
}

/* =========================================================================
 * 浮層：提示訊息、對話框、底部抽屜
 * ========================================================================= */
.toasts { position: fixed; z-index: 90; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
@media (max-width: 719px) { .toasts { bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom, 0px)); } }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-radius: 12px; background: var(--ink); color: var(--surface);
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow-lg); animation: toastIn .32s var(--ease-spring) both; pointer-events: auto;
}
.toast .ic { color: #6FE0A6; }
.toast.out { animation: toastOut .25s ease forwards; }
.scrim { position: fixed; inset: 0; z-index: 80; background: var(--scrim); animation: fadeIn .2s ease both; }
.scrim.out { animation: fadeOut .2s ease forwards; }
.modal {
  position: fixed; z-index: 81; inset: 0; margin: auto; width: min(440px, calc(100vw - 32px)); height: fit-content; max-height: calc(100dvh - 48px); overflow: auto;
  background: var(--surface); border-radius: 18px; padding: 22px; box-shadow: var(--shadow-lg);
  animation: modalIn .28s var(--ease-spring) backwards;
}
.modal.out { animation: modalOut .18s ease forwards; }
.modal h3 { font-size: 18px; }
.modal-body { margin-top: 10px; color: var(--ink-2); font-size: 14px; display: grid; gap: 14px; }
.modal-actions { margin-top: 20px; display: flex; justify-content: flex-end; gap: 8px; }
.sheet {
  position: fixed; z-index: 81; left: 0; right: 0; bottom: 0; max-height: 86dvh; overflow: auto;
  background: var(--surface); border-radius: 20px 20px 0 0; box-shadow: var(--shadow-lg);
  padding: 8px max(18px, env(safe-area-inset-right, 0px)) calc(18px + env(safe-area-inset-bottom, 0px)) max(18px, env(safe-area-inset-left, 0px));
  animation: sheetIn .36s var(--ease-out) backwards;
}
.sheet.out { animation: sheetOut .24s ease forwards; }
.sheet-grip { width: 40px; height: 4px; border-radius: 4px; background: var(--line-strong); margin: 4px auto 14px; }
.sheet h3 { font-size: 17px; margin-bottom: 14px; }
.sheet-section { display: grid; gap: 10px; margin-bottom: 18px; }
.sheet-section > span { font-size: 13px; font-weight: 600; color: var(--ink-2); }

/* =========================================================================
 * 重新連線視窗（Components/Layout/ReconnectModal.razor）
 * Blazor 在對話框加上連線狀態 class；每段內容的 data-for 列出在哪些狀態顯示，同一時間只顯示一種狀態。
 * retrying 會和 show 同時存在，所以 show 的內容要排除 retrying。
 * ========================================================================= */
.reconnect {
  width: min(400px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); margin: auto; padding: 24px;
  border: 0; border-radius: 18px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg);
  /* 短暫斷線（例如切回分頁馬上接回）不要閃一下：延遲一點才出現 */
  animation: modalIn .28s var(--ease-spring) .8s backwards;
}
/* 舊版瀏覽器的 ::backdrop 不繼承自訂屬性，所以附上淺色的底色 */
/* 開啟時焦點在對話框本身（裡面沒有可以操作的東西時），不需要外框 */
.reconnect:focus { outline: none; }
.reconnect::backdrop { background: var(--scrim, rgba(15, 27, 45, .42)); animation: fadeIn .2s ease .8s backwards; }
.reconnect [data-for] { display: none; }
.reconnect.components-reconnect-show:not(.components-reconnect-retrying) [data-for~="show"],
.reconnect.components-reconnect-retrying [data-for~="retrying"],
.reconnect.components-reconnect-failed [data-for~="failed"],
.reconnect.components-reconnect-rejected [data-for~="rejected"],
.reconnect.components-reconnect-paused [data-for~="paused"],
.reconnect.components-reconnect-resume-failed [data-for~="resume-failed"] { display: block; }
.reconnect.components-reconnect-failed .btn[data-for~="failed"],
.reconnect.components-reconnect-paused .btn[data-for~="paused"],
.reconnect.components-reconnect-resume-failed .btn[data-for~="resume-failed"] { display: inline-flex; }
.reconnect-mark { width: 46px; height: 46px; margin-bottom: 16px; border-radius: 14px; display: grid; place-items: center; background: var(--hero); color: var(--hero-brass); }
.reconnect-mark .ic { width: 24px; height: 24px; }
/* 正在連線或重新載入時圖示慢慢轉；連不上時改成警示色 */
.reconnect.components-reconnect-show .reconnect-mark .ic,
.reconnect.components-reconnect-rejected .reconnect-mark .ic { animation: spin 1.4s linear infinite; }
.reconnect:is(.components-reconnect-failed, .components-reconnect-resume-failed) .reconnect-mark { background: var(--bad-tint); color: var(--bad-ink); }
.reconnect h3 { font-size: 18px; }
.reconnect-text p { margin-top: 6px; color: var(--ink-2); font-size: 14px; line-height: 1.6; }
.reconnect-why { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.reconnect-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.reconnect:is(.components-reconnect-failed, .components-reconnect-paused, .components-reconnect-resume-failed) .reconnect-actions { margin-top: 20px; }

/* =========================================================================
 * 骨架載入
 * ========================================================================= */
.sk { border-radius: 12px; background: linear-gradient(90deg, var(--surface-3) 0%, var(--surface-2) 40%, var(--surface-3) 80%); background-size: 300% 100%; animation: shimmer 1.3s ease-in-out infinite; }
.sk-hero { height: 300px; border-radius: 22px; grid-column: span 12; }
.sk-card { height: 220px; }

/* =========================================================================
 * 進場與動畫
 * ========================================================================= */
/* 進場動畫用 backwards：結束後不留下 transform，否則卡片會變成 position: fixed 子元素的定位基準，
   自訂下拉選單的浮層就會被卡片蓋住或定位錯誤（對話框置中也因此不用 transform） */
.reveal { animation: rise .55s var(--ease-out) backwards; animation-delay: calc(var(--i, 0) * 55ms); }
/* 切換頁內分頁後不再逐張浮現（整塊用 panel-in 很快淡入），內容馬上就看得到，不會像卡住 */
.no-stagger .reveal { animation: none; }
/* 等待伺服器回應的讀取條（app.js：點了之後 0.15 秒內畫面還沒更新才出現） */
.busy-bar { position: fixed; z-index: 120; top: 0; left: 0; right: 0; height: 3px; pointer-events: none; opacity: 0; transition: opacity .15s; overflow: hidden; }
.busy-bar::after { content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 40%; background: var(--accent); border-radius: 0 3px 3px 0; animation: busySlide 1.1s var(--ease-out) infinite; }
.busy-bar.on { opacity: 1; }
@keyframes busySlide { from { transform: translateX(-100%); } to { transform: translateX(260%); } }
.page.leaving { animation: leave .14s ease forwards; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes leave { to { opacity: 0; transform: translateY(-4px); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes grow { to { transform: scaleY(1); } }
@keyframes growX { to { transform: scaleX(1); } }
@keyframes meterIn { from { transform: scaleX(0); } }
@keyframes pop { from { opacity: 0; transform: scale(.2); } to { opacity: 1; transform: scale(1); } }
@keyframes pulseRing { 0% { opacity: .7; transform: scale(1); } 100% { opacity: 0; transform: scale(3.2); } }
@keyframes ping { 0% { opacity: .8; transform: scale(.6); } 100% { opacity: 0; transform: scale(1.8); } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes modalOut { to { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes sheetIn { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sheetOut { to { transform: translateY(100%); } }
@keyframes rowFlash { 0% { background: var(--ok-tint); } 100% { background: var(--surface); } }

/* 尊重「減少動態效果」設定：保留最終狀態，取消過程 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  .pulse-ring, .dot.live::after { display: none; }
  .busy-bar::after { width: 100%; transform: none; animation: none; opacity: .6; }   /* 讀取條不滑動，整條淡色顯示 */
}

/* =========================================================================
 * 網站版補充（原型沒有的部分）
 * ========================================================================= */
/* 第一次連線完成前的骨架 */
.boot { position: fixed; inset: 0; z-index: 100; display: grid; place-content: center; justify-items: center; gap: 16px; background: var(--bg); }
.boot-mark { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: var(--hero); color: var(--hero-brass); animation: pulseSoft 1.4s ease-in-out infinite; }
.boot-mark .ic { width: 28px; height: 28px; }
@keyframes pulseSoft { 50% { transform: scale(.94); opacity: .8; } }
/* 載入中的頁面骨架 */
.page-loading { display: grid; gap: 20px; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.page-loading .sk-hero { grid-column: span 12; }
.page-loading .sk-card { grid-column: span 6; }
@media (max-width: 719px) { .page-loading .sk-card { grid-column: span 12; } }
/* 錯誤訊息 */
.form-error { color: var(--bad-ink); font-size: 13px; }
