/* ==========================================================================
   平衡豬 — 設計系統「存股帳本」
   米白紙色底、墨綠黑側欄、一個深青綠主色；台股慣例紅漲綠跌。
   股票深藍、債券土黃，明度差距大，色弱也分得出來。
   字型全部放在本機（IBM Plex Sans 只含拉丁字母與數字），中文用系統字型，PWA 離線時不會退字。
   ========================================================================== */

@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../vendor/fonts/ibm-plex-sans-latin-400.woff2') format('woff2');
}

@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../vendor/fonts/ibm-plex-sans-latin-500.woff2') format('woff2');
}

@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 600 700;
  font-display: swap;
  src: url('../vendor/fonts/ibm-plex-sans-latin-600.woff2') format('woff2');
}

:root,
[data-theme='light'] {
  /* --- 主色：深青綠（按鈕、選取狀態、焦點框）--- */
  --brand-700: #153f3b;
  --brand-600: #1a4f4a;
  --brand-500: #1f5c57;
  --brand-400: #2f7a73;
  --brand-200: #b9d3cf;
  --brand-100: #e3eeec;
  --brand-gradient: linear-gradient(#1f5c57, #1f5c57);
  --accent-fill: #1f5c57;
  --accent-fill-hover: #174a45;
  --on-accent: #ffffff;

  /* --- 紙色表面與墨色文字 --- */
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #efebe1;
  --surface-inset: #f7f4ec;
  --border: #e2dccf;
  --border-strong: #cfc6b3;
  --text: #1b1a17;
  --text-secondary: #57534a;
  --text-muted: #6b665b;

  /* --- 側欄 --- */
  --rail: #17211e;
  --rail-2: #24322e;
  --rail-line: #2c3a36;
  --rail-text: #e8e3d6;
  --rail-muted: #a7b0a8;

  /* --- 語意色（台股慣例：紅漲綠跌）--- */
  --buy: #b3261e;
  --buy-bg: #fbeae7;
  --sell: #2b6a45;
  --sell-bg: #e6f1ea;
  --warning: #8a4f06;
  --warning-bg: #fbf0dc;
  --warning-icon-bg: #f4ddb3;
  --danger: #a3261d;
  --danger-bg: #fbeae7;

  /* --- 資產類別 --- */
  --cat-stock: #2b4c7e;
  --cat-stock-bg: #e4eaf3;
  --cat-bond: #7a5a1c;
  --cat-bond-bg: #f5ecd9;
  --cat-stock-fill: #2b4c7e;
  --cat-bond-fill: #c49a4a;

  /* --- 圖表 --- */
  --chart-target: #d9d2c2;
  --chart-actual: #1f5c57;
  --chart-value: #1f5c57;
  --chart-value-fill: rgba(31, 92, 87, 0.08);
  --chart-invested: #57534a;
  --chart-bar: #b9d3cf;
  --chart-bar-empty: #e6e1d6;
  --tooltip-bg: #1b1a17;

  /* --- 圓角與陰影（帳本風格：扁平、只留很淡的陰影）--- */
  --radius-sm: 8px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-sm: none;
  --shadow: 0 1px 2px rgba(27, 26, 23, 0.04);
  --shadow-md: 0 6px 18px rgba(27, 26, 23, 0.06);
  --shadow-lg: 0 24px 60px rgba(23, 33, 30, 0.22);
  --shadow-brand: none;

  --font: 'IBM Plex Sans', 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', -apple-system, 'Segoe UI', sans-serif;
  --font-serif: 'Noto Serif TC', 'Songti TC', 'STSong', 'PMingLiU', 'MingLiU', serif;

  --transition: 160ms cubic-bezier(0.4, 0, 0.2, 1);

  color-scheme: light;
}

[data-theme='dark'] {
  --brand-700: #a6dad2;
  --brand-600: #8fd0c7;
  --brand-500: #6fbfb4;
  --brand-400: #4a9d93;
  --brand-200: #2a4a45;
  --brand-100: #1c302d;
  --brand-gradient: linear-gradient(#2e746c, #2e746c);
  --accent-fill: #2e746c;
  --accent-fill-hover: #37857c;
  --on-accent: #ffffff;

  --bg: #121816;
  --surface: #1a2220;
  --surface-2: #212b28;
  --surface-inset: #161d1b;
  --border: #2c3834;
  --border-strong: #3a4944;
  --text: #ece7db;
  --text-secondary: #c4beb0;
  --text-muted: #9a968a;

  --rail: #0d1311;
  --rail-2: #1c2724;
  --rail-line: #24302c;
  --rail-text: #e8e3d6;
  --rail-muted: #9aa39b;

  --buy: #f28b82;
  --buy-bg: #3a1d1a;
  --sell: #7cc49a;
  --sell-bg: #16291e;
  --warning: #e3a94a;
  --warning-bg: #33260f;
  --warning-icon-bg: #4a3712;
  --danger: #f28b82;
  --danger-bg: #3a1d1a;

  --cat-stock: #9fb6de;
  --cat-stock-bg: #1e2838;
  --cat-bond: #d9b46a;
  --cat-bond-bg: #332a17;
  --cat-stock-fill: #6f8fc6;
  --cat-bond-fill: #c9a55c;

  --chart-target: #3a4944;
  --chart-actual: #6fbfb4;
  --chart-value: #6fbfb4;
  --chart-value-fill: rgba(111, 191, 180, 0.1);
  --chart-invested: #c4beb0;
  --chart-bar: #2f5a54;
  --chart-bar-empty: #26302d;
  --tooltip-bg: #0d1311;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);

  color-scheme: dark;
}

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100dvh;
  background-color: var(--bg);
}

:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================================================
   排版
   ========================================================================== */

h1, h2, h3 {
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text);
}

h1 { font-size: 1.125rem; }
h2 { font-size: 0.9375rem; }
h3 { font-size: 0.875rem; }

.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
  text-align: right;
}

.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.8125rem; }

.label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   品牌與頁面容器
   ========================================================================== */

.brand-mark { flex-shrink: 0; }

.brand-title {
  font-size: 0.9375rem;
  font-weight: 650;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.015em;
}

.brand-sub {
  font-size: 0.6875rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  font-weight: 500;
}

.page {
  max-width: 1360px;
  margin: 0 auto;
  padding: 22px calc(24px + env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom))
    calc(24px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ==========================================================================
   卡片
   ========================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.card-head h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.card-head h2 svg { color: var(--brand-500); }

.card-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ==========================================================================
   版面
   ========================================================================== */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: start;
}

.layout > * { min-width: 0; }

.col {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ==========================================================================
   按鈕
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  min-height: 40px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 550;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: transform var(--transition), box-shadow var(--transition), background-color var(--transition),
    border-color var(--transition), color var(--transition);
}

.btn-primary {
  background: var(--brand-gradient);
  color: #fff;
  box-shadow: var(--shadow-brand);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(99, 102, 241, 0.42);
}

.btn-primary:active:not(:disabled) { transform: none; }

.btn-secondary {
  background: var(--surface);
  color: var(--text-secondary);
  border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-inset);
  color: var(--text);
  border-color: var(--brand-400);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) { filter: brightness(1.08); }

.btn-lg {
  padding: 13px 22px;
  min-height: 50px;
  font-size: 0.9375rem;
}

.btn-block { width: 100%; }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition);
}

.icon-btn:hover:not(:disabled) {
  background: var(--brand-100);
  color: var(--brand-600);
}

.icon-btn.danger:hover:not(:disabled) {
  background: var(--danger-bg);
  color: var(--danger);
}

.icon-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ==========================================================================
   表單
   ========================================================================== */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.input {
  width: 100%;
  padding: 9px 12px;
  min-height: 42px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 16px; /* 16px 防止 iOS / iPadOS Safari 點擊輸入框時自動縮放頁面 */
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  touch-action: manipulation;
}

.input:hover:not(:disabled) { border-color: var(--brand-400); }

.input:focus {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.16);
}

.input.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%238189a6' stroke-width='1.6' d='m1 1.5 5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.input[type='number'] { -moz-appearance: textfield; }

.input[type='number']::-webkit-outer-spin-button,
.input[type='number']::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ==========================================================================
   報告摘要
   ========================================================================== */

.report-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-inset);
}

.report-summary-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.report-summary-item .label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.report-summary-item .val-buy,
.report-summary-item .val-sell {
  font-size: 1rem;
  font-weight: 700;
}

@media (max-width: 480px) {
  .report-summary { grid-template-columns: 1fr; }
}

/* ==========================================================================
   表格
   ========================================================================== */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.table th {
  padding: 11px 16px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-inset);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table th.num { text-align: right; }

.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background-color var(--transition); }
.table tbody tr:hover td { background: var(--brand-100); }

.cell-title { font-weight: 600; color: var(--text); }
.cell-sub { font-size: 0.75rem; color: var(--text-muted); }

/* ==========================================================================
   標籤
   ========================================================================== */

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 550;
  line-height: 1.45;
  white-space: nowrap;
}

.tag-buy { background: var(--buy-bg); color: var(--buy); }
.tag-sell { background: var(--sell-bg); color: var(--sell); }
.tag-warning { background: var(--warning-bg); color: var(--warning); }
.tag-danger { background: var(--danger-bg); color: var(--danger); }
.tag-neutral { background: var(--surface-inset); color: var(--text-muted); }

.val-buy { color: var(--buy); font-weight: 600; }
.val-sell { color: var(--sell); font-weight: 600; }
/* 損益：台股慣例賺錢紅色、賠錢綠色，與買進 / 賣出同色 */
.pnl-up { color: var(--buy); font-weight: 600; }
.pnl-down { color: var(--sell); font-weight: 600; }

/* ==========================================================================
   提示訊息
   ========================================================================== */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  line-height: 1.65;
}

.alert svg { flex-shrink: 0; margin-top: 2px; }

.alert-danger { background: var(--danger-bg); color: var(--danger); }
.alert-warning { background: var(--warning-bg); color: var(--warning); }
.alert-info { background: var(--brand-100); color: var(--text-secondary); }

.alert-note {
  background: var(--surface-inset);
  border-left: 3px solid var(--brand-500);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-secondary);
  white-space: pre-wrap;
  font-size: 0.8125rem;
  padding: 12px 14px;
  line-height: 1.7;
}

.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* 同步狀態 */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 6px 11px;
  border-radius: var(--radius-full);
  background: var(--surface-inset);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.status.ok { color: var(--sell); background: var(--sell-bg); border-color: transparent; }
.status.err { color: var(--danger); background: var(--danger-bg); border-color: transparent; }

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--brand-gradient);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
}

/* ==========================================================================
   工具類
   ========================================================================== */

.row { display: flex; align-items: center; gap: 8px; }
.row-end { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* ==========================================================================
   圖表
   ========================================================================== */

.chart-canvas {
  position: relative;
  width: 100%;
  min-height: 180px;
}

.chart-empty {
  display: flex;
  min-height: 160px;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.8125rem;
  background: var(--surface-inset);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

/* ==========================================================================
   執行紀錄
   ========================================================================== */

.history-item { border-bottom: 1px solid var(--border); }
.history-item:last-child { border-bottom: none; }

.history-item > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 20px;
  cursor: pointer;
  list-style: none;
  transition: background-color var(--transition);
}

.history-item > summary::-webkit-details-marker { display: none; }
.history-item > summary:hover { background: var(--brand-100); }

.history-chevron {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform var(--transition);
}

.history-item[open] > summary { background: var(--surface-inset); }
.history-item[open] .history-chevron { transform: rotate(180deg); }

.history-detail { padding: 4px 20px 16px; }

.history-detail .table td {
  padding: 8px 0;
  font-size: 0.8125rem;
}

/* ==========================================================================
   彈窗
   ========================================================================== */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(23, 20, 55, 0.5);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
  animation: overlay-in 140ms ease-out;
}

.modal {
  width: 100%;
  max-height: calc(100dvh - 40px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: modal-in 190ms cubic-bezier(0.2, 0, 0.2, 1);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 17px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 15px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.fade-in { animation: fade-in 260ms ease-out; }

@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 900ms linear infinite; }

/* ==========================================================================
   登入頁
   ========================================================================== */

.auth-shell {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 36px 30px;
  text-align: center;
}

.auth-mark {
  margin: 0 auto 18px;
  display: block;
  filter: drop-shadow(0 8px 18px rgba(99, 102, 241, 0.35));
}

.auth-card h1 {
  font-size: 1.3125rem;
  margin-bottom: 8px;
}

.auth-tagline { margin: -4px 0 20px; color: var(--text-secondary); font-size: 0.9375rem; }

/* Google 品牌按鈕：白底、灰框，符合其品牌規範 */
.btn-google {
  background: #fff;
  color: #1f1f1f;
  border-color: #dadce0;
  font-weight: 500;
}

.btn-google:hover:not(:disabled) { background: #f7f8f8; border-color: #c9ccd1; }

/* ==========================================================================
   PWA 提示與離線列
   ========================================================================== */

.toast-zone {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 70;
  width: min(460px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 15px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  font-size: 0.8125rem;
  animation: modal-in 220ms ease-out;
}

.toast > svg { color: var(--brand-500); flex-shrink: 0; }

.offline-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--warning-bg);
  color: var(--warning);
  font-size: 0.8125rem;
  font-weight: 500;
}

/* ==========================================================================
   資產卡片（資產部位手機與平板版專用排版，取代通用的表格轉列表樣式）
   ========================================================================== */

.asset-card-list {
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
  padding: 16px;
}

.asset-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--surface-inset);
  box-shadow: var(--shadow-sm);
}

.asset-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.asset-card-ratio { margin-bottom: 14px; }

.asset-card-ratio-labels {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 7px;
}

.asset-card-ratio-labels .text-xs { margin-left: auto; }

.asset-card-bar {
  position: relative;
  width: 100%;
  height: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
}

.asset-card-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--brand-gradient);
  transition: width 300ms ease;
}

.asset-card-bar-fill.over { background: var(--danger); }
.asset-card-bar-fill.under { background: var(--sell); }

.asset-card-bar-target {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 14px;
  background: var(--text);
  border-radius: 1px;
  transform: translateX(-1px);
}

.asset-card-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.asset-card-footer {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.asset-card-value {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text);
}

.asset-table-desktop .table {
  min-width: 820px;
}

/* ==========================================================================
   RWD 響應式佈局系統（特別針對 iPad mini 6、iPad 系列與各尺寸螢幕優化）
   ========================================================================== */

/* 1180px 以下：平板橫向與中型螢幕（如 iPad mini 6 橫向 1133px、iPad 橫向 1080px） */
@media (max-width: 1180px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  
}

/* 960px 以下：平板直向（如 iPad mini 6 直向 744px、iPad 直向 768px/820px/834px）與手機 */
@media (max-width: 960px) {
  .page {
    padding: 16px calc(16px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom))
      calc(16px + env(safe-area-inset-left));
    gap: 16px;
  }

  

  .card-head { padding: 14px 16px; }
  .card-body { padding: 16px; gap: 14px; }

  /* 資產部位在平板直向與手機切換為卡片式網格排版，絕不爆版擠壓 */
  .asset-table-desktop { display: none; }
  .asset-card-list { display: grid; }

  

  /* 觸控目標放大至 44px */
  .btn { min-height: 44px; padding: 10px 16px; }
  .icon-btn { width: 42px; height: 42px; }
  .input { min-height: 44px; }

  .modal .table {
    min-width: 680px;
  }
}

/* 640px 以下：手機版專用調整 */
@media (max-width: 640px) {
  .brand-sub { display: none; }

  

  
  
  
  
  

  .field-grid { grid-template-columns: 1fr; }

  .asset-card-list {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 10px;
  }

  .report-summary {
    grid-template-columns: 1fr;
  }

  .overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal {
    max-height: 92dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: none;
    animation: sheet-in 240ms cubic-bezier(0.2, 0, 0.2, 1);
  }

  .modal-foot {
    padding-bottom: calc(15px + env(safe-area-inset-bottom));
    flex-direction: column-reverse;
  }

  .modal-foot .btn { width: 100%; }

  /* 彈窗內的執行報告表格在手機版轉為單卡片呈現 */
  .modal .table-wrap { overflow-x: visible; }

  .modal .table,
  .modal .table tbody,
  .modal .table tr,
  .modal .table td {
    display: block;
    width: 100%;
  }

  .modal .table { min-width: 0; }
  .modal .table thead { display: none; }

  .modal .table tbody tr {
    border-bottom: 1px solid var(--border);
    padding: 12px 14px;
    background: var(--surface-inset);
    border-radius: var(--radius);
    margin-bottom: 10px;
  }

  .modal .table tbody tr:last-child { margin-bottom: 0; }
  .modal .table tbody tr:hover td { background: transparent; }

  .modal .table td {
    padding: 5px 0;
    border-bottom: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    text-align: right;
  }

  .modal .table td::before {
    content: attr(data-label);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
  }

  .modal .table td[data-label='標的'] {
    display: block;
    text-align: left;
    padding-bottom: 8px;
    margin-bottom: 4px;
    border-bottom: 1px dashed var(--border);
  }

  .modal .table td[data-label='標的']::before { display: none; }

  .modal .table td[data-label='說明'] {
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    gap: 4px;
    padding-top: 8px;
    border-top: 1px dashed var(--border);
    margin-top: 4px;
  }

  .modal .table td[data-label='說明']::before {
    font-weight: 600;
  }

  .toast-zone { width: calc(100vw - 24px); }
}

@keyframes sheet-in {
  from { opacity: 0; transform: translateY(28px); }
  to { opacity: 1; transform: none; }
}

/* 480px 以下：小螢幕手機微調 */
@media (max-width: 480px) {
  

  .hide-sm { display: none; }
  .status span { display: none; }
  .status { padding: 7px; }
}

/* 380px 以下：超窄手機 */
@media (max-width: 380px) {
  
  .asset-card-fields { grid-template-columns: 1fr; }
}

/* ==========================================================================
   列印
   ========================================================================== */

@media print {
  .app-shell { display: block; }
  .rail,
  .bottom-tabs,
  .toast-zone,
  .icon-btn,
  .btn { display: none !important; }

  body { background: #fff; background-image: none; }
  .card { border-color: #ccc; box-shadow: none; break-inside: avoid; }
  .overlay { position: static; background: none; padding: 0; backdrop-filter: none; }
  .modal { box-shadow: none; max-height: none; border: none; }
}

/* ==========================================================================
   同步狀態：離線暫存
   ========================================================================== */

.status.warn { color: var(--warning); background: var(--warning-bg); border-color: transparent; }

/* ==========================================================================
   標的編輯視窗：各月入帳配息輸入與快捷工具
   ========================================================================== */

.dividend-input-box {
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dividend-preset-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.monthly-grid-container {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.monthly-grid-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: all var(--transition);
}

.monthly-grid-cell.has-val {
  border-color: var(--brand-400);
  background: var(--brand-100);
}

.monthly-cell-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 2px;
  white-space: nowrap;
}

.monthly-grid-cell.has-val .monthly-cell-label {
  color: var(--brand-700);
}

.input-xs {
  height: 28px !important;
  font-size: 0.8125rem !important;
  padding: 2px 4px !important;
  text-align: center;
}

.dividend-summary-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
  flex-wrap: wrap;
}

@media (max-width: 600px) {
  .monthly-grid-container {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 420px) {
  .monthly-grid-container {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ==========================================================================
   再平衡頁籤樣式
   ========================================================================== */

.rebalance-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

.rebalance-col {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

/* ==========================================================================
   全裝置 RWD 響應式優化 (針對 iPad mini 6 744px、一般平板與手機完美排版)
   ========================================================================== */

/* 1180px 以下 (中大尺寸螢幕 / iPad 橫向) */

/* 960px 以下 (iPad mini 6 744px 直向、iPad 768px/820px 直向) */
@media (max-width: 960px) {
  .rebalance-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  

  

  

  
}

/* 640px 以下 (手機螢幕) */

/* ==========================================================================
   Spring Boot 版補充：帳號密碼登入與註冊（React 版只有 Google 登入）
   ========================================================================== */

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  border-top: 1px solid var(--border);
}

.auth-links {
  margin-top: 18px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.auth-links a {
  color: var(--brand-600);
  font-weight: 600;
  text-decoration: none;
}

.auth-links a:hover { text-decoration: underline; }

.alert-success { background: var(--sell-bg); color: var(--sell); }

.auth-theme-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
}

/* ==========================================================================
   Spring Boot 版補充：標的編輯視窗的自訂入帳月份（取代 React 版固定的配息週期按鈕）
   ========================================================================== */

.month-chip-row {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 4px;
}

.month-chip {
  min-height: 30px;
  padding: 4px 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color var(--transition), border-color var(--transition), color var(--transition);
}

.month-chip:hover { border-color: var(--brand-400); color: var(--brand-600); }

.month-chip.active {
  background: var(--brand-gradient);
  border-color: transparent;
  color: #fff;
  box-shadow: var(--shadow-brand);
}

@media (max-width: 600px) {
  .month-chip-row { grid-template-columns: repeat(6, 1fr); }
  .month-chip { min-height: 36px; }
}

/* ==========================================================================
   存股帳本：版面骨架
   桌機：左側選單（品牌、組合、分頁、同步與帳號）+ 內容。
   900px 以下：左側選單收成頂列（組合改成橫向捲動），分頁移到畫面下方。
   ========================================================================== */

.app-shell {
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  min-height: 100dvh;
}

.rail {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 100dvh;
  overflow-y: auto;
  background: var(--rail);
  color: var(--rail-text);
  padding: calc(28px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.rail-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 6px;
}

.rail .brand-title {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--rail-text);
}

.rail .brand-sub {
  margin-top: 2px;
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  color: var(--rail-muted);
}

.rail-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rail-label {
  padding: 0 14px;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  color: var(--rail-muted);
}

.rail-portfolios {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rail-portfolio {
  display: flex;
  align-items: stretch;
  border-radius: 12px;
  transition: background-color var(--transition);
}

.rail-portfolio.active { background: var(--rail-2); }
.rail-portfolio:not(.active):hover { background: rgba(255, 255, 255, 0.04); }

.rail-portfolio-btn {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  padding: 10px 6px 10px 14px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--rail-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.rail-portfolio:not(.active) .rail-portfolio-btn { color: var(--rail-muted); }

.rail-portfolio-name {
  font-size: 0.875rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail-portfolio-sub {
  font-size: 0.78rem;
  color: var(--rail-muted);
  font-variant-numeric: tabular-nums;
}

.rail-portfolio-more {
  width: 36px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--rail-muted);
  cursor: pointer;
}

.rail-portfolio-more:hover { color: var(--rail-text); background: rgba(255, 255, 255, 0.06); }

.rail-add {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  margin-top: 4px;
  padding: 0 14px;
  border: 1px dashed var(--rail-line);
  border-radius: 12px;
  background: transparent;
  color: var(--rail-muted);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
}

.rail-add:hover { color: var(--rail-text); border-color: var(--rail-muted); }

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rail-nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 44px;
  padding: 0 14px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--rail-text);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--transition);
}

.rail-nav-btn:hover { background: rgba(255, 255, 255, 0.05); }
.rail-nav-btn.active { background: var(--accent-fill); color: var(--on-accent); }

.nav-badge {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--rail-muted);
  font-variant-numeric: tabular-nums;
}

.rail-nav-btn.active .nav-badge { color: rgba(255, 255, 255, 0.85); }

.nav-badge.warn {
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: #f0c877;
  color: #1b1a17;
  font-weight: 600;
}

.rail-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rail-sync {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 6px;
}

.rail .status,
.rail .status.ok,
.rail .status.err,
.rail .status.warn {
  padding: 4px 6px;
  border: none;
  background: transparent;
  color: var(--rail-muted);
}

.rail .status.ok { color: #8fd3aa; }
.rail .status.err { color: #f4a39c; }
.rail .status.warn { color: #f0c877; }

.btn.btn-rail {
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--rail-line);
  background: transparent;
  color: var(--rail-text);
  font-size: 0.8125rem;
}

.btn.btn-rail:hover:not(:disabled) { border-color: var(--rail-muted); background: rgba(255, 255, 255, 0.04); }

.rail-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 6px 0;
  border-top: 1px solid var(--rail-line);
}

.rail .avatar {
  width: 34px;
  height: 34px;
  background: var(--rail-2);
  color: var(--rail-text);
  font-size: 0.875rem;
}

.rail-user-text { flex: 1; min-width: 0; }

.rail-user-name,
.rail-user-sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail-user-name { font-size: 0.875rem; font-weight: 600; }
.rail-user-sub { font-size: 0.75rem; color: var(--rail-muted); }

.icon-btn.icon-btn-rail { width: 36px; height: 36px; color: var(--rail-muted); }
.icon-btn.icon-btn-rail:hover:not(:disabled) { background: rgba(255, 255, 255, 0.08); color: var(--rail-text); }

.app-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.page {
  width: 100%;
  max-width: 1280px;
  padding: 40px calc(48px + env(safe-area-inset-right)) calc(48px + env(safe-area-inset-bottom)) 48px;
  gap: 24px;
}

.bottom-tabs { display: none; }

/* ==========================================================================
   存股帳本：頁首、卡片、按鈕與表單
   ========================================================================== */

.stack-lg {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px 24px;
}

.page-eyebrow {
  font-size: 0.8125rem;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.page-title {
  margin-top: 6px;
  font-family: var(--font-serif);
  font-size: 1.875rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.01em;
}

.page-sub {
  max-width: 760px;
  margin-top: 8px;
  font-size: 0.9375rem;
  color: var(--text-secondary);
}

.page-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.page-hint {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.page-hint svg { flex-shrink: 0; margin-top: 2px; color: var(--text-muted); }

.link-btn {
  padding: 0;
  border: none;
  background: none;
  color: var(--brand-500);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.card:hover { box-shadow: var(--shadow); }

.card-head {
  padding: 20px 24px 0;
  border-bottom: none;
}

.card-head h2 { font-size: 1.0625rem; font-weight: 700; letter-spacing: 0; }
.card-head h2 svg { color: var(--text-muted); }
.card-head + .table-wrap { margin-top: 12px; }

.card-body { padding: 20px 24px 24px; }

.welcome-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 36px;
}

.welcome-card .page-title { margin: 0; font-size: 1.5rem; }

.btn { font-weight: 600; }

.btn-primary,
.btn-primary:hover:not(:disabled) {
  background: var(--accent-fill);
  color: var(--on-accent);
  box-shadow: none;
  transform: none;
}

.btn-primary:hover:not(:disabled) { background: var(--accent-fill-hover); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-inset);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-outline {
  background: var(--surface);
  color: var(--brand-500);
  border-color: var(--brand-500);
}

.btn-outline:hover:not(:disabled) { background: var(--brand-100); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost.danger { color: var(--danger); }

.btn-lg { min-height: 48px; padding: 0 20px; font-size: 0.9375rem; }
.btn-md { min-height: 44px; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: 0.8125rem; }
.btn-xs { min-height: 28px; padding: 4px 10px; font-size: 0.75rem; }

.icon-btn { width: 36px; height: 36px; border-radius: 8px; }
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.input:hover:not(:disabled) { border-color: var(--border-strong); }
.input:focus { border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(31, 92, 87, 0.15); }
.input-sm { min-height: 34px; padding: 4px 10px; }

.tag {
  padding: 2px 9px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tag-neutral { background: var(--surface-2); color: var(--text-secondary); }

.table tbody tr:hover td { background: var(--surface-inset); }

.alert-row {
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.seg-group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-2);
}

.seg-btn {
  flex: 1;
  min-width: 56px;
  min-height: 36px;
  padding: 0 14px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--accent-fill); color: var(--on-accent); }

/* 類別色點與圖例 */
.cat-dot,
.legend-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.cat-dot { font-size: 0.78rem; color: var(--text-secondary); }

.cat-dot::before,
.legend-dot::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--cat-stock-fill);
}

.cat-dot.bond::before,
.legend-dot.bond::before { background: var(--cat-bond-fill); }

/* ==========================================================================
   存股帳本：總覽
   ========================================================================== */

.hero-card {
  display: grid;
  grid-template-columns: 1.25fr 1fr 1.2fr;
  padding: 28px 32px;
}

.hero-cell {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 28px;
}

.hero-cell:first-child { padding-left: 0; }
.hero-cell:last-child { padding-right: 0; }
.hero-cell + .hero-cell { border-left: 1px solid var(--border); }

.hero-label { font-size: 0.875rem; color: var(--text-secondary); }

.hero-value {
  font-size: 2.75rem;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.hero-value-md {
  font-size: 2.125rem;
  font-weight: 600;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.hero-idle { display: inline-flex; align-items: center; gap: 6px; }

.hero-inline-input {
  width: 9ch;
  padding: 0 0 1px;
  border: none;
  border-bottom: 1.5px dashed var(--border-strong);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}

.hero-inline-input:focus { outline: none; border-bottom-color: var(--brand-500); }

.hero-inline-input::-webkit-outer-spin-button,
.hero-inline-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.split-bar {
  position: relative;
  height: 12px;
  margin: 4px 0 2px;
  border-radius: var(--radius-full);
  background: var(--cat-bond-fill);
}

.split-bar-stock {
  height: 100%;
  border-radius: var(--radius-full) 0 0 var(--radius-full);
  background: var(--cat-stock-fill);
}

.split-bar-target {
  position: absolute;
  top: -5px;
  width: 2px;
  height: 22px;
  background: var(--text);
  transform: translateX(-1px);
}

.rebalance-banner {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 20px 24px;
  border-radius: var(--radius-lg);
}

.rebalance-banner.is-warn { background: var(--warning-bg); }
.rebalance-banner.is-ok { background: var(--surface); border: 1px solid var(--border); }

.rebalance-banner-icon {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
}

.is-warn .rebalance-banner-icon { background: var(--warning-icon-bg); color: var(--warning); }
.is-ok .rebalance-banner-icon { background: var(--sell-bg); color: var(--sell); }

.rebalance-banner-text { flex: 1; min-width: 0; }
.rebalance-banner-title { font-size: 1.0625rem; font-weight: 700; color: var(--text); }

.rebalance-banner-sub {
  margin-top: 4px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.rebalance-banner-actions { display: flex; flex-shrink: 0; gap: 10px; }

.overview-grid {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 4fr);
  gap: 24px;
  align-items: start;
}

/* 配置：目標 vs 實際 */
.alloc-legend {
  display: flex;
  gap: 14px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.alloc-legend span { display: inline-flex; align-items: center; gap: 6px; }
.alloc-legend-target { display: inline-block; width: 2px; height: 14px; background: var(--text); }
.alloc-legend-band { display: inline-block; width: 18px; height: 10px; border-radius: 4px; background: var(--brand-100); }

.card-body.alloc-list { gap: 20px; }

.alloc-row {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) 150px;
  grid-template-areas: 'name track figs';
  align-items: center;
  gap: 20px;
}

.alloc-name { grid-area: name; min-width: 0; }
.alloc-name .cell-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.8125rem; }
.alloc-track { grid-area: track; position: relative; height: 30px; }

.alloc-rail {
  position: absolute;
  top: 11px;
  left: 0;
  right: 0;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
}

.alloc-band { position: absolute; top: 7px; height: 16px; border-radius: 6px; background: var(--brand-100); }

.alloc-fill {
  position: absolute;
  top: 11px;
  left: 0;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--cat-stock-fill);
}

.alloc-fill.bond { background: var(--cat-bond-fill); }

.alloc-target {
  position: absolute;
  top: 3px;
  width: 2px;
  height: 24px;
  background: var(--text);
  transform: translateX(-1px);
}

.alloc-figures {
  grid-area: figs;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

.alloc-axis { margin-top: -8px; font-size: 0.75rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.alloc-axis > span:first-child { grid-area: name; }
.alloc-axis > div { grid-area: track; display: flex; justify-content: space-between; }

/* 組合健康度 */
.health-score { display: flex; align-items: baseline; gap: 6px; }

.health-score-val {
  font-size: 3.25rem;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.health-score-unit { color: var(--text-muted); }

.health-bar {
  height: 8px;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--surface-2);
}

.health-bar-fill { height: 100%; border-radius: var(--radius-full); transition: width 300ms ease; }
.health-bar-fill.optimal { background: var(--sell); }
.health-bar-fill.attention { background: var(--cat-bond-fill); }
.health-bar-fill.warning { background: var(--warning); }

.health-advice { font-size: 0.9rem; line-height: 1.6; color: var(--text-secondary); }

.health-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.health-stat-label { font-size: 0.78rem; color: var(--text-muted); }

.health-stat-val {
  margin-top: 2px;
  font-size: 1.0625rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* 未來 12 個月股息 */
.div-head-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.div-head-stats strong { color: var(--text); }

.div-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 28px;
  align-items: stretch;
}

.div-bars {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 6px;
  align-items: end;
}

.div-bar-btn {
  height: 196px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding: 8px 0 6px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  cursor: pointer;
  transition: background-color var(--transition);
}

.div-bar-btn:hover { background: var(--surface-inset); }
.div-bar-btn.active { background: var(--surface-2); color: var(--text); }

.div-bar-val { font-size: 0.75rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.div-bar-btn.active .div-bar-val { color: var(--text); font-weight: 600; }

.div-bar { width: min(26px, 70%); border-radius: 6px; background: var(--chart-bar-empty); }
.div-bar-btn.has .div-bar { background: var(--chart-bar); }
.div-bar-btn.active .div-bar { background: var(--accent-fill); }

.div-bar-label { font-size: 0.8125rem; white-space: nowrap; }
.div-bar-btn.active .div-bar-label { font-weight: 700; }

.div-bar-btn.current .div-bar-label {
  text-decoration: underline;
  text-decoration-color: var(--brand-400);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

.div-detail {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  border-radius: 14px;
  background: var(--bg);
}

.div-detail-label { font-size: 0.875rem; color: var(--text-secondary); }
.div-detail-value { font-size: 1.875rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.div-detail-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.div-detail-item { display: flex; justify-content: space-between; gap: 12px; font-size: 0.875rem; }
.div-detail-amt { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }

.div-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 24px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* ==========================================================================
   存股帳本：部位表格
   ========================================================================== */

.holdings-card { overflow: hidden; }

.holdings-table th { padding: 14px 10px; background: transparent; font-size: 0.78rem; }
.holdings-table td { padding: 14px 10px; }

.holdings-table th:first-child,
.holdings-table td:first-child { padding-left: 24px; }

.holdings-table th:last-child,
.holdings-table td:last-child { padding-right: 16px; }

.holdings-table tfoot td {
  padding: 16px 10px;
  border-top: 1px solid var(--border-strong);
  font-size: 0.875rem;
  font-weight: 600;
}

.holdings-table tfoot td:first-child { padding-left: 24px; }

.ticker-sub { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; margin-top: 3px; }

.cell-stack { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }

.cell-note {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: nowrap;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--text-secondary);
  white-space: nowrap;
}

.nowrap { white-space: nowrap; }

.cell-strong { font-size: 0.9375rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.cell-with-unit { display: inline-flex; align-items: center; gap: 6px; }

.input.input-cell {
  width: 92px;
  min-height: 36px;
  padding: 4px 10px;
  border-color: transparent;
  border-bottom: 1px dashed var(--border-strong);
  border-radius: 8px 8px 0 0;
  background: var(--surface-inset);
  font-size: 0.9375rem;
}

.input.input-cell:hover:not(:disabled) { border-color: transparent; border-bottom-color: var(--brand-400); }
.input.input-cell:focus { border-color: var(--brand-500); border-radius: 8px; }
.input.input-cell-sm { width: 64px; }

.asset-card-bar-fill.stock { background: var(--cat-stock-fill); }
.asset-card-bar-fill.bond { background: var(--cat-bond-fill); }

/* ==========================================================================
   存股帳本：歷史回測
   ========================================================================== */

.bt-controls {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 16px 24px;
  padding: 20px 24px;
}

.bt-controls > .field { width: 200px; }
.bt-controls > .field:first-child { width: auto; }
.bt-run { margin-left: auto; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
}

.kpi {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.kpi-label { font-size: 0.84rem; color: var(--text-secondary); }

.kpi-value {
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.kpi-note { font-size: 0.78rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.chart-legend { display: flex; gap: 18px; font-size: 0.8125rem; color: var(--text-secondary); }
.chart-legend span { display: inline-flex; align-items: center; gap: 8px; }
.legend-line { display: inline-block; width: 18px; border-top: 3px solid var(--chart-value); }
.legend-line.invested { border-top: 2px dashed var(--chart-invested); }

.bt-bottom {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 24px;
  align-items: start;
}

.notes-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-left: 18px;
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

/* ==========================================================================
   存股帳本：彈窗與標的編輯
   ========================================================================== */

.overlay { background: rgba(23, 33, 30, 0.55); }
.modal { border-radius: 18px; }
.modal-head h2 { font-family: var(--font-serif); font-size: 1.3rem; font-weight: 700; }
.modal-foot { background: var(--surface); }

.dividend-input-box {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border: none;
  border-radius: 14px;
  background: var(--bg);
}

.dividend-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.dividend-title { font-size: 0.9375rem; font-weight: 700; }
.alert.dividend-source { margin: 0; font-size: 0.8125rem; line-height: 1.6; }

.monthly-grid-container {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.monthly-grid-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.monthly-grid-cell.has-val { border-color: var(--brand-200); background: var(--brand-100); }
.monthly-cell-label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); }
.monthly-grid-cell.has-val .monthly-cell-label { color: var(--text); }

.monthly-grid-cell .input {
  min-height: 28px;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  text-align: left;
}

.monthly-grid-cell.has-val .input { font-weight: 600; }

.dividend-quick > summary {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.dividend-quick-body { display: flex; flex-direction: column; gap: 10px; padding-top: 10px; }

.dividend-preset-input-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }

.auth-card h1 { font-family: var(--font-serif); font-weight: 700; }
.auth-mark { filter: none; }

/* ==========================================================================
   存股帳本：響應式
   ========================================================================== */

@media (max-width: 1280px) {
  .page { padding-left: 32px; padding-right: calc(32px + env(safe-area-inset-right)); }
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 244px minmax(0, 1fr); }
  .overview-grid, .bt-bottom { grid-template-columns: minmax(0, 1fr); }
  .div-layout { grid-template-columns: minmax(0, 1fr) 260px; }
  .asset-table-desktop { display: none; }
  .asset-card-list { display: grid; }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }

  .rail {
    height: auto;
    overflow: visible;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 12px;
    padding: calc(10px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) 10px calc(14px + env(safe-area-inset-left));
  }

  .rail-brand { padding: 0; }
  .rail-brand-text { display: none; }
  .rail-nav { display: none; }

  .rail-foot { flex-direction: row; align-items: center; gap: 4px; margin: 0 0 0 auto; }
  .rail-sync { padding: 0; }
  .rail-user { gap: 0; padding: 0; border-top: none; }
  .rail-user-text, .rail .avatar { display: none; }

  .rail-section { order: 5; width: 100%; }
  .rail-label { display: none; }

  .rail-portfolios {
    flex-direction: row;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .rail-portfolios::-webkit-scrollbar { display: none; }
  .rail-portfolio { flex-shrink: 0; border: 1px solid var(--rail-line); }
  .rail-portfolio-btn { min-height: 40px; padding: 6px 4px 6px 12px; }
  .rail-portfolio-sub { display: none; }
  .rail-portfolio-more { width: 32px; }
  .rail-add { flex-shrink: 0; height: auto; min-height: 42px; margin-top: 0; white-space: nowrap; }

  .page {
    padding: 16px calc(16px + env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
    gap: 16px;
  }

  .stack-lg { gap: 16px; }
  .page-title { font-size: 1.5rem; }

  .bottom-tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    padding: 4px calc(8px + env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left));
    border-top: 1px solid var(--border);
    background: var(--surface);
  }

  .bottom-tab {
    position: relative;
    flex: 1;
    min-height: 56px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
  }

  .bottom-tab.active { color: var(--brand-500); font-weight: 700; }

  .bottom-tab-dot {
    position: absolute;
    top: 8px;
    right: calc(50% - 16px);
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--warning);
  }

  .hero-card { grid-template-columns: minmax(0, 1fr); gap: 16px; padding: 20px; }
  .hero-cell { padding: 0; }
  .hero-cell + .hero-cell { padding-top: 16px; border-left: none; border-top: 1px solid var(--border); }
  .hero-value { font-size: 2.25rem; }
  .hero-value-md { font-size: 1.75rem; }

  .rebalance-banner { flex-wrap: wrap; align-items: flex-start; gap: 12px 14px; padding: 16px; }
  .rebalance-banner-text { flex: 1 1 200px; }
  .rebalance-banner-actions { width: 100%; }
  .rebalance-banner-actions .btn { flex: 1; }

  .card-head { padding: 16px 16px 0; }
  .card-body { padding: 16px; }

  .alloc-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: 'name figs' 'track track'; gap: 4px 12px; }
  .alloc-axis { display: none; }

  .div-layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .div-bars { gap: 2px; }
  .div-bar-btn { height: 150px; }
  .div-bar-val { font-size: 0.625rem; }
  .div-bar-label { font-size: 0.6875rem; }

  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .kpi { padding: 16px; }
  .kpi-value { font-size: 1.375rem; }
  .bt-controls { padding: 16px; }
  .bt-controls > .field { width: 100%; }
  .bt-run { width: 100%; margin-left: 0; }
}

@media (max-width: 640px) {
  .monthly-grid-container { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .div-bar-val { display: none; }
}

@media (max-width: 380px) {
  .monthly-grid-container { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* 數字欄不換行；窄螢幕時回測的期末持股表格改為左右捲動 */
.table td.num,
.table th.num { white-space: nowrap; }
.bt-bottom .table { min-width: 560px; }

/* ==========================================================================
   存股帳本：手機與平板細修
   ========================================================================== */

.page-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }

.hero-idle-field { display: inline-flex; align-items: baseline; }

/* 手機版的組合下拉選單；桌機用左側清單 */
.mobile-portfolio { display: none; }

/* 左側選單的分頁文字不換行，標籤不被擠壓 */
.rail-nav-btn > span:not(.nav-badge) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-badge { flex-shrink: 0; white-space: nowrap; }

/* 表格收成卡片清單時，外層不再是一張卡片（避免卡片裡再包卡片） */
@media (max-width: 1180px) {
  .holdings-card {
    overflow: visible;
    border: none;
    background: transparent;
    box-shadow: none;
  }

  .holdings-card .asset-card-list { padding: 0; }
}

/* 平板直向：總資產一整列，損益與股債比並排 */
@media (min-width: 601px) and (max-width: 900px) {
  .hero-card { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 24px; }
  .hero-cell:first-child { grid-column: 1 / -1; }
  .hero-cell:nth-child(3) { padding-left: 24px; border-left: 1px solid var(--border); }
}

@media (max-width: 900px) {
  /* 內容比螢幕短時，多出來的高度給內容區，頂列維持原本高度 */
  .app-shell { grid-template-rows: auto 1fr; }
  .rail { position: sticky; top: 0; flex-wrap: nowrap; gap: 10px; }
  .rail-section { display: none; }

  .mobile-portfolio {
    display: block;
    flex: 1;
    min-width: 0;
    height: 44px;
    padding: 0 34px 0 12px;
    border: 1px solid var(--rail-line);
    border-radius: 10px;
    background-color: var(--rail-2);
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%23e8e3d6' stroke-width='1.6' d='m1 1.5 5 5 5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    color: var(--rail-text);
    font: inherit;
    font-size: 16px; /* 16px 防止 iOS Safari 點選時自動放大 */
    font-weight: 600;
    text-overflow: ellipsis;
    appearance: none;
    -webkit-appearance: none;
  }

  .rail-foot { flex-shrink: 0; margin: 0; }
}

@media (max-width: 600px) {
  .page-head { gap: 12px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
}

@media (max-width: 640px) {
  .div-bar-unit { display: none; }
  .div-bar-label { font-size: 0.75rem; }
}

/* ==========================================================================
   網頁導覽與操作手冊
   導覽：圈選框用大範圍的 box-shadow 把其餘畫面變暗，外圈金色呼吸光；
   氣泡是圓角對話框，小豬撲滿在左上角輕輕上下晃，尾巴指向圈選的區塊。
   ========================================================================== */

.rail-help { display: flex; flex-direction: column; gap: 8px; }
.rail-help-icon { display: inline-flex; }
.rail-help-btn { color: var(--rail-muted); text-decoration: none; }
.rail-help-btn:hover { color: var(--rail-text); }

.tour {
  position: fixed;
  inset: 0;
  z-index: 1000;
  opacity: 0;
  transition: opacity 200ms ease;
  font-family: var(--font);
}

.tour.tour-in { opacity: 1; }
.tour.tour-out { opacity: 0; pointer-events: none; }
html.tour-open { overscroll-behavior: none; }
/* 導覽期間內容底下多留空白，頁尾的區塊也能捲到氣泡放得下的位置 */
html.tour-open .app-main { padding-bottom: 60vh; }

.tour-blocker { position: absolute; inset: 0; cursor: default; }

.tour-spot {
  position: absolute;
  border-radius: 14px;
  box-shadow: 0 0 0 200vmax var(--tour-dim);
  pointer-events: none;
  transition: top 380ms cubic-bezier(0.3, 0.9, 0.3, 1), left 380ms cubic-bezier(0.3, 0.9, 0.3, 1),
    width 380ms cubic-bezier(0.3, 0.9, 0.3, 1), height 380ms cubic-bezier(0.3, 0.9, 0.3, 1), border-radius 380ms ease;
}

/* 金色外框 + 呼吸光圈，標出目前在講哪一塊 */
.tour-spot::before,
.tour-spot::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: inherit;
  border: 3px solid #f3cf7a;
}

.tour-spot::after {
  border-width: 2px;
  opacity: 0;
  animation: tour-breathe 1.8s ease-out infinite;
}

.tour-center .tour-spot::before,
.tour-center .tour-spot::after { display: none; }

@keyframes tour-breathe {
  0% { inset: -3px; opacity: 0.9; }
  100% { inset: -14px; opacity: 0; }
}

.tour-bubble {
  position: absolute;
  width: min(372px, calc(100vw - 24px));
  padding: 18px 20px 20px;
  border: 2px solid var(--tour-edge);
  border-radius: 24px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28), 0 3px 0 var(--tour-edge);
  outline: none;
  transition: top 380ms cubic-bezier(0.3, 0.9, 0.3, 1), left 380ms cubic-bezier(0.3, 0.9, 0.3, 1), opacity 140ms ease;
}

.tour-bubble.tour-leaving { opacity: 0; }

.tour-bubble.tour-pop { animation: tour-pop 420ms cubic-bezier(0.34, 1.56, 0.64, 1); }
.tour-bubble[data-side='bottom'] { transform-origin: 50% 0; }
.tour-bubble[data-side='top'] { transform-origin: 50% 100%; }
.tour-bubble[data-side='right'] { transform-origin: 0 50%; }
.tour-bubble[data-side='left'] { transform-origin: 100% 50%; }

@keyframes tour-pop {
  0% { opacity: 0; transform: scale(0.82); }
  60% { opacity: 1; transform: scale(1.03); }
  100% { transform: scale(1); }
}

.tour-bubble.tour-wiggle { animation: tour-wiggle 420ms ease; }

@keyframes tour-wiggle {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-2.5deg); }
  45% { transform: rotate(2deg); }
  70% { transform: rotate(-1deg); }
}

/* 尾巴：轉 45 度的小方塊，只畫朝外的兩條邊 */
.tour-tail {
  position: absolute;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  background: var(--surface);
  border: 2px solid var(--tour-edge);
  transform: rotate(45deg);
  display: none;
}

.tour-bubble[data-side='bottom'] .tour-tail { display: block; top: 0; border-right: none; border-bottom: none; }
.tour-bubble[data-side='top'] .tour-tail { display: block; top: 100%; border-left: none; border-top: none; }
.tour-bubble[data-side='right'] .tour-tail { display: block; left: 0; border-top: none; border-right: none; }
.tour-bubble[data-side='left'] .tour-tail { display: block; left: 100%; border-bottom: none; border-left: none; }

.tour-mascot {
  float: left;
  width: 64px;
  height: 64px;
  margin: -2px 12px 4px -4px;
  border-radius: 50%;
  background: var(--tour-halo);
  display: grid;
  place-items: center;
}

.tour-piggy { width: 52px; height: 46px; overflow: visible; animation: tour-bob 2.4s ease-in-out infinite; }
.tour-piggy-coin { animation: tour-coin 2.4s ease-in-out infinite; }
.tour-piggy-eye { transform-origin: 26px 30px; animation: tour-blink 4s infinite; }

@keyframes tour-bob {
  0%, 100% { transform: translateY(1px) rotate(-2deg); }
  50% { transform: translateY(-3px) rotate(2deg); }
}

@keyframes tour-coin {
  0%, 100% { transform: translateY(-2px); }
  50% { transform: translateY(3px); }
}

@keyframes tour-blink {
  0%, 92%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.1); }
}

.tour-count {
  float: right;
  margin: 2px 0 0 8px;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tour-count:empty { display: none; }

.tour-title {
  margin: 6px 0 6px;
  font-family: var(--font-serif);
  font-size: 1.1875rem;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: 0.01em;
}

.tour-body {
  clear: left;
  color: var(--text-secondary);
  font-size: 0.9375rem;
  line-height: 1.7;
}

.tour-body p { margin: 0; }
.tour-body p + p { margin-top: 6px; }

/* 重點用螢光筆畫線的樣子 */
.tour-body b {
  color: var(--text);
  font-weight: 600;
  background: linear-gradient(transparent 58%, var(--tour-marker) 0);
  padding: 0 1px;
}

.tour-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 16px;
}

/* 進度條：貼在氣泡底部的細長條 */
.tour-progress {
  position: absolute;
  left: 22px;
  right: 22px;
  bottom: 7px;
  height: 3px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  overflow: hidden;
}

.tour-progress i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #e4b660;
  transition: width 380ms cubic-bezier(0.3, 0.9, 0.3, 1);
}

.tour-center .tour-progress { display: none; }

.tour-btns { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.tour-btn {
  min-height: 38px;
  padding: 0 16px;
  border: none;
  border-radius: var(--radius-full);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--transition), transform 120ms ease;
}

.tour-btn:active { transform: scale(0.96); }
.tour-btn-main { background: var(--accent-fill); color: var(--on-accent); box-shadow: 0 2px 0 var(--brand-700); }
.tour-btn-main:hover { background: var(--accent-fill-hover); }
.tour-btn-soft { background: var(--brand-100); color: var(--brand-700); }
.tour-btn-soft:hover { background: var(--brand-200); }
.tour-btn-ghost { margin-left: -8px; padding: 0 8px; background: transparent; color: var(--text-muted); }
.tour-btn-ghost:hover { color: var(--text); }
.tour-btn:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }

:root,
[data-theme='light'] {
  --tour-dim: rgba(14, 20, 18, 0.62);
  --tour-edge: #eadcc0;
  --tour-halo: #fbe9e1;
  --tour-marker: rgba(243, 207, 122, 0.55);
}

[data-theme='dark'] {
  --tour-dim: rgba(0, 0, 0, 0.74);
  --tour-edge: #3d4a45;
  --tour-halo: #3a2c29;
  --tour-marker: rgba(196, 154, 74, 0.45);
}

.tour-still .tour-spot,
.tour-still .tour-bubble { transition: none; }
.tour-still .tour-spot::after,
.tour-still .tour-piggy,
.tour-still .tour-piggy-coin,
.tour-still .tour-piggy-eye { animation: none; }

@media (max-width: 480px) {
  .tour-bubble { padding: 16px 16px 18px; border-radius: 20px; }
  .tour-mascot { width: 54px; height: 54px; margin-right: 10px; }
  .tour-piggy { width: 44px; height: 39px; }
  .tour-title { font-size: 1.0625rem; }
  .tour-body { font-size: 0.875rem; }
  .tour-btn { min-height: 40px; padding: 0 14px; }
}

/* ---------- 網站操作手冊（彈窗） ---------- */

.manual-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px;
  border: 2px solid var(--tour-edge);
  border-radius: 20px;
  background: var(--surface-inset);
}

.manual-hero .tour-mascot { float: none; flex-shrink: 0; margin: 0; }
.manual-hero-text { flex: 1; min-width: 0; }
.manual-hero-title { font-family: var(--font-serif); font-size: 1.0625rem; font-weight: 700; }
.manual-hero-sub { margin-top: 2px; color: var(--text-secondary); font-size: 0.875rem; line-height: 1.6; }
.manual-hero .tour-btn { flex-shrink: 0; }

.manual-list { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }

.manual-item {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.manual-item[open] { border-color: var(--border-strong); }

.manual-item > summary {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 10px 14px;
  cursor: pointer;
  list-style: none;
  font-weight: 600;
}

.manual-item > summary::-webkit-details-marker { display: none; }

.manual-item-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 10px;
  background: var(--brand-100);
  color: var(--brand-600);
  display: grid;
  place-items: center;
}

.manual-item-title { flex: 1; min-width: 0; }
.manual-item-chev { color: var(--text-muted); transition: transform var(--transition); display: inline-flex; }
.manual-item[open] .manual-item-chev { transform: rotate(180deg); }

.manual-item-body {
  padding: 0 14px 14px 58px;
  color: var(--text-secondary);
  font-size: 0.875rem;
  line-height: 1.7;
}

.manual-item-body ul { margin: 0; padding-left: 1.1em; }
.manual-item-body li + li { margin-top: 4px; }
.manual-item-body strong { color: var(--text); font-weight: 600; }

.manual-show {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 6px 12px;
  border: 1px dashed var(--brand-400);
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--brand-600);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}

.manual-show:hover { background: var(--brand-100); border-style: solid; }

.manual-foot-note { margin-top: 14px; color: var(--text-muted); font-size: 0.8125rem; line-height: 1.6; }

@media (max-width: 600px) {
  .manual-hero { flex-wrap: wrap; }
  .manual-hero .tour-btn { width: 100%; }
  .manual-item-body { padding-left: 14px; }
}

/* 手機與直向平板：操作手冊收成頂列的圖示按鈕 */
@media (max-width: 900px) {
  .rail-help { flex-shrink: 0; }
  .rail-help .rail-label,
  .rail-help-text { display: none; }

  .rail-help-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    justify-content: center;
    border-radius: 8px;
  }

  .rail-help-btn:hover { background: rgba(255, 255, 255, 0.08); }
}

@media print {
  .rail-help,
  .tour { display: none !important; }
}

/* ==========================================================================
   公開頁面：介紹頁、教學文章、條款
   與主畫面同一套紙色與墨綠，版面置中、最寬 1080px；文章內文最寬 720px。
   ========================================================================== */

.site-body { display: flex; flex-direction: column; min-height: 100dvh; background: var(--bg); }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.2) blur(8px);
}

.site-header-inner,
.site-footer-inner,
.site-main {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding-left: calc(24px + env(safe-area-inset-left));
  padding-right: calc(24px + env(safe-area-inset-right));
}

.site-header-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 64px; }

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 1.0625rem;
  font-weight: 700;
  text-decoration: none;
}

.site-nav { display: flex; align-items: center; gap: 6px; }
.site-nav > a:not(.btn) { padding: 8px 10px; border-radius: 8px; color: var(--text-secondary); font-size: 0.9375rem; text-decoration: none; }
.site-nav > a:not(.btn):hover { background: var(--surface-2); color: var(--text); }
.site-nav .btn { text-decoration: none; }

.site-main { flex: 1; padding-top: 48px; padding-bottom: 64px; }

.site-footer { border-top: 1px solid var(--border); background: var(--surface-inset); }
.site-footer-inner { padding-top: 28px; padding-bottom: calc(28px + env(safe-area-inset-bottom)); display: grid; gap: 12px; }
.site-footer-note { max-width: 760px; margin: 0; color: var(--text-muted); font-size: 0.8125rem; line-height: 1.7; }
.site-footer-links { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.site-footer-links a { color: var(--text-secondary); font-size: 0.875rem; text-decoration: none; }
.site-footer-links a:hover { color: var(--text); text-decoration: underline; }
.site-footer-copy { margin: 0; color: var(--text-muted); font-size: 0.8125rem; }

/* ---------- 介紹頁 ---------- */

.landing-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  align-items: center;
  gap: 48px;
  padding: 16px 0 56px;
}

.landing-title {
  margin: 8px 0 16px;
  font-family: var(--font-serif);
  font-size: clamp(1.5rem, 3.4vw, 2.5rem);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.01em;
}

/* 標題每個子句不從中間斷開，放不下才整句換行 */
.landing-title span { display: inline-block; }

.landing-lead { max-width: 560px; margin: 0; color: var(--text-secondary); font-size: 1.0625rem; line-height: 1.8; }
.landing-cta { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 28px; }
.landing-cta .btn { text-decoration: none; }
.landing-note { margin: 14px 0 0; color: var(--text-muted); font-size: 0.875rem; line-height: 1.7; }

.landing-demo {
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.landing-demo-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; }
.landing-demo-tag { padding: 3px 10px; border-radius: var(--radius-full); background: var(--sell-bg); color: var(--sell); font-size: 0.75rem; font-weight: 600; }
.landing-demo-ratio { display: grid; gap: 8px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.landing-demo-ratio-label { display: flex; align-items: baseline; gap: 10px; font-size: 0.875rem; }
.landing-demo-ratio-label strong { font-size: 1.25rem; }
.landing-demo-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 12px; font-variant-numeric: tabular-nums; }
.landing-demo-row strong { min-width: 56px; text-align: right; }
.landing-demo-foot { display: flex; justify-content: space-between; gap: 12px; padding-top: 12px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 0.8125rem; }

.landing-section { padding: 40px 0; border-top: 1px solid var(--border); }
.landing-section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.landing-h2 { margin: 0 0 24px; font-family: var(--font-serif); font-size: 1.5rem; font-weight: 700; }

.landing-features { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }

.landing-feature {
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.landing-feature h3 { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 14px 0 8px; font-size: 1.0625rem; }
.landing-feature p { margin: 0; color: var(--text-secondary); font-size: 0.9375rem; line-height: 1.7; }

.landing-feature-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--brand-100);
  color: var(--brand-600);
  display: grid;
  place-items: center;
}

.landing-badge { padding: 2px 8px; border-radius: var(--radius-full); background: var(--surface-2); color: var(--text-muted); font-size: 0.6875rem; font-weight: 600; }

.landing-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin: 0; padding: 0; list-style: none; counter-reset: step; }

.landing-steps li {
  counter-increment: step;
  display: grid;
  gap: 6px;
  padding: 22px;
  border-radius: var(--radius-lg);
  background: var(--surface-inset);
  border: 1px solid var(--border);
}

.landing-steps li::before {
  content: counter(step);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-fill);
  color: var(--on-accent);
  display: grid;
  place-items: center;
  font-weight: 700;
  margin-bottom: 6px;
}

.landing-steps span { color: var(--text-secondary); font-size: 0.9375rem; line-height: 1.7; }

/* ---------- 教學文章 ---------- */

.guide-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.guide-list-wide { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.guide-card {
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition: border-color var(--transition), transform var(--transition);
}

.guide-card:hover { border-color: var(--brand-400); transform: translateY(-2px); }
.guide-card h3 { margin: 0; font-family: var(--font-serif); font-size: 1.0625rem; line-height: 1.5; }
.guide-card p { margin: 0; color: var(--text-secondary); font-size: 0.875rem; line-height: 1.7; }

.guide-index-head { max-width: 720px; margin-bottom: 32px; }
.guide-index-head h1 { margin: 8px 0 12px; font-family: var(--font-serif); font-size: 2rem; }

.prose { max-width: 720px; margin: 0 auto; color: var(--text); font-size: 1.0625rem; line-height: 1.9; }
.prose h1 { margin: 8px 0 8px; font-family: var(--font-serif); font-size: clamp(1.625rem, 3.6vw, 2.125rem); line-height: 1.4; }
.prose h2 { margin: 40px 0 12px; font-family: var(--font-serif); font-size: 1.375rem; line-height: 1.5; }
.prose p { margin: 0 0 16px; }
.prose ul, .prose ol { margin: 0 0 16px; padding-left: 1.4em; }
.prose li + li { margin-top: 6px; }
.prose a { color: var(--brand-600); }
.prose strong { font-weight: 600; }
.prose-meta { margin: 0 0 28px !important; color: var(--text-muted); font-size: 0.875rem; }
.prose-head { margin-bottom: 8px; }
.prose-table { margin: 0 0 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-size: 0.9375rem; line-height: 1.6; }
.prose-table td, .prose-table th { white-space: normal; }
.prose-callout { margin: 0 0 24px; font-size: 0.9375rem; line-height: 1.8; }
.prose .ad-slot { margin: 32px 0; }

.breadcrumb { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 0.875rem; }
.breadcrumb a { color: var(--text-secondary); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

.guide-cta {
  max-width: 720px;
  margin: 40px auto 0;
  padding: 22px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 2px solid var(--tour-edge);
  border-radius: var(--radius-lg);
  background: var(--surface-inset);
}

.guide-cta-title { font-family: var(--font-serif); font-size: 1.125rem; font-weight: 700; }
.guide-cta p { margin: 4px 0 0; color: var(--text-secondary); font-size: 0.9375rem; }
.guide-cta .btn { flex-shrink: 0; text-decoration: none; }
.guide-related { max-width: 1080px; margin: 48px auto 0; }
.guide-related h2 { margin: 0 0 16px; font-family: var(--font-serif); font-size: 1.25rem; }
.site-main > .ad-slot { max-width: 720px; margin: 32px auto; }

/* ---------- 廣告版位 ---------- */

.ad-slot { display: grid; gap: 4px; }
.ad-slot-label { color: var(--text-muted); font-size: 0.6875rem; letter-spacing: 0.08em; }

.ad-slot-box {
  min-height: 100px;
  display: grid;
  place-items: center;
  padding: 16px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.8125rem;
  text-align: center;
}

/* ---------- 主畫面的頁尾與廣告 ---------- */

.app-ad { width: 100%; max-width: 1280px; padding: 0 calc(48px + env(safe-area-inset-right)) 0 48px; }

.app-foot {
  width: 100%;
  max-width: 1280px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 20px;
  padding: 16px calc(48px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) 48px;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.app-foot nav { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.app-foot a { color: var(--text-muted); }
.app-foot a:hover { color: var(--text); }

/* ---------- 試用模式、需要帳號的區塊、帳號設定 ---------- */

.rail-guest-actions { display: flex; gap: 8px; padding: 0 6px; }
.rail-guest-actions .btn { flex: 1; justify-content: center; text-decoration: none; }
.btn.btn-rail-primary { gap: 0; border-color: transparent; background: #f3cf7a; color: #1b1a17; font-weight: 700; }
.btn.btn-rail-primary:hover:not(:disabled) { background: #f6da96; }

.locked-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 8px 16px;
  padding: 24px;
}

.locked-card-icon {
  grid-row: span 2;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--warning-bg);
  color: var(--warning);
  display: grid;
  place-items: center;
}

.locked-card-text h2 { margin: 0 0 6px; font-size: 1.0625rem; }
.locked-card-text p { margin: 0; color: var(--text-secondary); font-size: 0.9375rem; line-height: 1.7; }
.locked-card-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.locked-card-actions .btn { text-decoration: none; }

.signup-hero { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.signup-hero .tour-mascot { float: none; flex-shrink: 0; margin: 0; }
.signup-hero p { margin: 0; line-height: 1.7; }
.signup-list { margin: 0 0 12px; padding: 0; list-style: none; display: grid; gap: 8px; }
.signup-list li { display: flex; align-items: flex-start; gap: 8px; color: var(--text-secondary); font-size: 0.9375rem; line-height: 1.6; }
.signup-list li svg { flex-shrink: 0; margin-top: 4px; color: var(--sell); }
.modal-foot a.btn { text-decoration: none; }

.account-head { padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.account-name { font-size: 1.125rem; font-weight: 700; }
.account-section { display: grid; gap: 10px; padding: 18px 0; border-bottom: 1px solid var(--border); }
.account-section:last-child { border-bottom: none; padding-bottom: 4px; }
.account-section h3 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 0.9375rem; }
.account-section p { margin: 0; color: var(--text-secondary); font-size: 0.875rem; line-height: 1.7; }
.account-section > .btn { justify-self: start; }
.account-danger h3 { color: var(--danger); }

.auth-legal { margin: 16px 0 0; color: var(--text-muted); font-size: 0.75rem; line-height: 1.8; }
.auth-legal a { color: var(--text-muted); }
.auth-consent { margin: 0; line-height: 1.7; }
.auth-consent a { color: var(--brand-600); }
.cf-turnstile { min-height: 65px; }

@media (max-width: 1180px) {
  .landing-features { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .landing-hero { grid-template-columns: minmax(0, 1fr); gap: 32px; padding-top: 0; }
  .guide-list { grid-template-columns: minmax(0, 1fr); }
  .guide-list-wide { grid-template-columns: minmax(0, 1fr); }
  .app-ad { padding: 0 calc(16px + env(safe-area-inset-right)) 0 calc(16px + env(safe-area-inset-left)); }
  .app-foot { padding: 8px calc(16px + env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); }
  .page { padding-bottom: 8px; }

  /* 頂列放不下：登出收進「帳號設定」，試用模式只留「免費註冊」 */
  .rail-logout, .rail-logout button { display: none !important; }
  .rail-guest-actions { padding: 0; }
  .rail-guest-actions .btn:not(.btn-rail-primary) { display: none; }
  .rail-guest-actions .btn-rail-primary { min-height: 36px; padding: 6px 12px; white-space: nowrap; }
}

@media (max-width: 640px) {
  .site-main { padding-top: 28px; padding-bottom: 40px; }
  .site-header-inner, .site-footer-inner, .site-main { padding-left: calc(16px + env(safe-area-inset-left)); padding-right: calc(16px + env(safe-area-inset-right)); }
  .site-brand span { display: none; }
  .landing-features, .landing-steps { grid-template-columns: minmax(0, 1fr); }
  .landing-cta .btn { flex: 1 1 100%; }
  .guide-cta { flex-direction: column; align-items: stretch; }
  .prose { font-size: 1rem; }
  .locked-card { grid-template-columns: minmax(0, 1fr); }
  .locked-card-icon { grid-row: auto; }
}

/* 左下角的頭像與名稱是「帳號設定」按鈕 */
.rail-user-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 4px 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.rail-user-btn:hover { background: rgba(255, 255, 255, 0.05); }
.rail-user-btn .rail-user-text { display: flex; flex-direction: column; }
.rail-user-btn-icon { display: none; }

@media (max-width: 900px) {
  .rail-user-btn { flex: 0 0 auto; width: 36px; height: 36px; padding: 0; justify-content: center; color: var(--rail-muted); }
  .rail-user-btn-icon { display: inline-flex; }
  .rail-user-btn .rail-user-text,
  .rail-user-btn .avatar { display: none; }
}

/* 窄手機：頂列空間不夠，「儲存」按鈕收起來（停手 1.2 秒就會自動存），註冊按鈕只寫「註冊」 */
@media (max-width: 480px) {
  .rail-sync .btn-rail { display: none; }
  .rail-free { display: none; }
}

/* ==========================================================================
   理財工具（/tools）、方案、電子報、後台
   ========================================================================== */

.hint { color: var(--text-muted); font-size: 0.75rem; line-height: 1.5; }

/* ---------- 工具總覽 ---------- */

.tools-filter { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.tools-cats { flex-wrap: wrap; }
.tools-search { max-width: 320px; }
.tools-empty { color: var(--text-muted); }

.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }

.tool-tile {
  position: relative;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition: border-color var(--transition), transform var(--transition);
}

.tool-tile:hover { border-color: var(--brand-400); transform: translateY(-2px); }
.tool-tile[hidden] { display: none; }
.tool-tile h2 { margin: 0; font-size: 1.0625rem; line-height: 1.45; }
.tool-tile p { margin: 0; color: var(--text-secondary); font-size: 0.875rem; line-height: 1.65; }
.tool-tile-cat { color: var(--brand-600); font-size: 0.75rem; font-weight: 600; }
.tool-tile-badge { position: absolute; top: 16px; right: 16px; padding: 2px 8px; border-radius: var(--radius-full); background: #f3cf7a; color: #1b1a17; font-size: 0.6875rem; font-weight: 700; }

/* ---------- 單一工具頁 ---------- */

.tool-head { max-width: 760px; margin-bottom: 24px; }
.tool-head h1 { margin: 8px 0 10px; font-family: var(--font-serif); font-size: clamp(1.5rem, 3.4vw, 2.125rem); line-height: 1.35; }

.tool-card { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 28px; padding: 28px; }
.tool-form { min-width: 0; }
.tool-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px 16px; }
.tool-fields .field .label { font-weight: 600; }

.tool-result { min-width: 0; display: grid; align-content: start; gap: 16px; transition: opacity 120ms ease; }
.tool-result.is-busy { opacity: 0.55; }
.tool-loading { color: var(--text-muted); }
.tool-result .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tool-result .kpi { padding: 16px 18px; }
.tool-result .kpi-value { font-size: 1.5rem; }
.tool-result .alert { margin: 0; }
.tool-verdict { font-size: 1rem; }
.tool-chart { position: relative; height: 260px; }
.tool-table { margin: 0; }
.tool-details summary { cursor: pointer; color: var(--brand-600); font-weight: 600; padding: 4px 0; }
.tool-details[open] summary { margin-bottom: 10px; }
.tool-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.tool-explain { margin-top: 40px; }

.compare-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.compare-card { padding: 16px 18px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.compare-card.is-best { border: 2px solid var(--sell); background: var(--sell-bg); }
.compare-title { font-weight: 700; }
.compare-value { margin: 6px 0; font-size: 1.375rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.compare-card ul { margin: 0; padding-left: 1.1em; color: var(--text-secondary); font-size: 0.8125rem; line-height: 1.7; }

.faq-list { display: grid; gap: 8px; margin-bottom: 16px; }
.faq { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 0 16px; }
.faq summary { cursor: pointer; padding: 14px 0; font-weight: 600; font-size: 1rem; }
.faq p { margin: 0 0 14px; color: var(--text-secondary); font-size: 0.9375rem; }

/* 快速再平衡的標的列 */
.rq-rows { display: grid; gap: 8px; margin-bottom: 10px; }
.rq-head, .rq-row { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 0.9fr) minmax(0, 1fr) minmax(0, 1.1fr) 32px; gap: 6px; align-items: center; }
.rq-head { color: var(--text-muted); font-size: 0.75rem; }
.rq-row .input { min-height: 38px; padding: 6px 8px; font-size: 15px; }
.rq-settings { margin-top: 16px; }

/* ---------- 方案 ---------- */

.pricing-head { text-align: center; margin: 0 auto 32px; }
.plan-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; max-width: 880px; margin: 0 auto; }
.plan-card { display: grid; align-content: start; gap: 16px; padding: 28px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.plan-premium { border: 2px solid var(--tour-edge); background: var(--surface-inset); }
.plan-name { font-family: var(--font-serif); font-size: 1.375rem; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.plan-soon { padding: 3px 10px; border-radius: var(--radius-full); background: #f3cf7a; color: #1b1a17; font-family: var(--font); font-size: 0.75rem; }
.plan-price { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.plan-price strong { font-size: 2rem; font-variant-numeric: tabular-nums; }
.plan-price span { color: var(--text-muted); font-size: 0.875rem; }
.plan-list { margin: 0; padding-left: 1.2em; display: grid; gap: 8px; color: var(--text-secondary); line-height: 1.6; }
.plan-muted { color: var(--text-muted); }
.plan-list a { color: var(--brand-600); }
.plan-next { color: var(--text-muted); font-size: 0.875rem; }
.plan-card .btn { text-decoration: none; justify-content: center; }
.plan-waitlist { display: grid; gap: 8px; }
.plan-waitlist-row, .newsletter-row { display: flex; gap: 8px; }
.plan-waitlist-row .btn, .newsletter-row .btn { flex-shrink: 0; }
.pricing-faq { margin-top: 48px; }

/* ---------- 電子報 ---------- */

.newsletter-card { max-width: 600px; margin: 0 auto; display: grid; gap: 14px; padding: 32px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.newsletter-card h1 { margin: 0; font-family: var(--font-serif); font-size: 1.75rem; }
.newsletter-card p { margin: 0; }
.newsletter-card .btn { justify-self: start; text-decoration: none; }
.newsletter-form { display: grid; gap: 10px; }

/* ---------- 後台 ---------- */

.admin-main { max-width: 1080px; }
.admin-wide { max-width: 1280px; }
.admin-title { margin: 0 0 12px; font-family: var(--font-serif); font-size: 1.75rem; }
.admin-head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.admin-head-row .btn { text-decoration: none; }
.admin-nav { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 20px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.admin-nav a { padding: 8px 12px; border-radius: 8px; color: var(--text-secondary); text-decoration: none; font-size: 0.9375rem; }
.admin-nav a:hover { background: var(--surface-2); color: var(--text); }
.admin-nav a.active { background: var(--accent-fill); color: var(--on-accent); }
.admin-main > .alert, .admin-main .alert { margin-bottom: 16px; }
.admin-kpis { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 20px; }
.admin-kpis .kpi { color: var(--text); text-decoration: none; }
.admin-card { padding: 20px 22px; margin-bottom: 20px; display: grid; gap: 14px; }
.admin-card h2 { margin: 0; font-size: 1.0625rem; }
.admin-subtitle { margin: 24px 0 10px; font-size: 1.0625rem; }
.admin-checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.admin-checklist li { display: flex; gap: 10px; align-items: flex-start; }
.admin-check-mark { flex: none; width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 0.8125rem; font-weight: 600; }
.admin-checklist li.ok .admin-check-mark { background: var(--brand-100); color: var(--accent-fill); }
.admin-checklist li.warn .admin-check-mark { background: var(--danger-bg); color: var(--danger); }
.admin-checklist li.todo .admin-check-mark { background: var(--warning-bg); color: var(--warning); }
.admin-checklist .cell-sub { overflow-wrap: anywhere; }
.plan-buy { margin: 0 0 10px; }
.plan-promo { margin: -4px 0 10px; color: var(--accent-fill); }
.account-sub { display: grid; gap: 8px; }
.account-sub p { margin: 0; }
.switch-row { display: flex; align-items: center; gap: 8px; font-size: 0.9375rem; cursor: pointer; }
.switch-row input { width: 18px; height: 18px; accent-color: var(--accent-fill); }
.admin-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.admin-actions .btn { text-decoration: none; }
.admin-search { display: flex; gap: 8px; max-width: 480px; margin-bottom: 8px; }
.admin-inline { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.admin-inline .input-xs { width: 90px; }
.admin-form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; align-items: end; }
.admin-editor { display: grid; gap: 14px; }
.editor-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.editor-body { min-height: 520px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; line-height: 1.7; resize: vertical; }
.editor-preview { max-width: none; min-height: 520px; max-height: 720px; overflow: auto; padding: 16px 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-size: 1rem; }
.admin-danger-zone { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--border); }
.account-plan { margin-top: 8px; font-size: 0.875rem; }
.account-plan a { color: var(--brand-600); }

@media (max-width: 900px) {
  .tool-card { grid-template-columns: minmax(0, 1fr); padding: 20px; }
  .plan-grid { grid-template-columns: minmax(0, 1fr); }
  .editor-split { grid-template-columns: minmax(0, 1fr); }
  .admin-form-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

@media (max-width: 640px) {
  .site-nav-extra { display: none; }
  .tool-fields { grid-template-columns: minmax(0, 1fr); }
  .compare-grid { grid-template-columns: minmax(0, 1fr); }
  .tools-search { max-width: none; }
  .rq-head { display: none; }
  /* 手機：每一檔排成兩列三欄（代號、類別、目標 / 市價、股數、移除） */
  .rq-row { grid-template-columns: repeat(3, minmax(0, 1fr)); padding-bottom: 8px; border-bottom: 1px solid var(--border); }
  .rq-row .icon-btn { justify-self: end; }
  .newsletter-card { padding: 22px; }
  .admin-form-grid { grid-template-columns: minmax(0, 1fr); }
}

/* 工具結果的表格：欄位不換行，窄螢幕改左右捲動；分類頁籤在窄螢幕改成可以左右滑動的一列 */
.tool-table { overflow-x: auto; }
.tool-table .table th, .tool-table .table td { white-space: nowrap; }
.tools-cats .seg-btn { flex: 0 0 auto; }

@media (max-width: 640px) {
  .tools-cats { flex-wrap: nowrap; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .tools-cats::-webkit-scrollbar { display: none; }
}

/* ==========================================================================
   管理後台：獨立的外框與配色（冷灰色系、深藍灰側欄），和前台的紙色、墨綠一眼就分得出來
   ========================================================================== */

.admin-body {
  --admin-bg: #eef0f3;
  --admin-side: #1c2331;
  --admin-side-2: #283142;
  --admin-side-text: #e6e9ef;
  --admin-side-muted: #9aa3b2;
  --admin-accent: #3f6fd8;
  min-height: 100dvh;
  background: var(--admin-bg);
}

[data-theme='dark'] .admin-body {
  --admin-bg: #12161d;
  --admin-side: #0b0f16;
  --admin-side-2: #1a212d;
}

.admin-shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100dvh; }

.admin-sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 14px;
  background: var(--admin-side);
  color: var(--admin-side-text);
}

.admin-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.admin-brand-title { font-weight: 700; font-size: 1rem; }
.admin-brand-sub { color: var(--admin-side-muted); font-size: 0.75rem; }

.admin-menu { display: flex; flex-direction: column; gap: 2px; }
.admin-menu a { padding: 10px 12px; border-radius: 8px; color: var(--admin-side-text); text-decoration: none; font-size: 0.9375rem; }
.admin-menu a:hover { background: var(--admin-side-2); }
.admin-menu a.active { background: var(--admin-accent); color: #fff; font-weight: 600; }

.admin-sidebar-foot { margin-top: auto; display: grid; gap: 10px; padding: 0 8px; }
.admin-side-link { color: var(--admin-side-muted); font-size: 0.875rem; text-decoration: none; }
.admin-side-link:hover { color: var(--admin-side-text); }
.admin-who { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 10px; border-top: 1px solid var(--admin-side-2); }
.admin-who-name { font-weight: 600; font-size: 0.875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn.admin-theme { color: var(--admin-side-muted); }
.icon-btn.admin-theme:hover { background: var(--admin-side-2); color: var(--admin-side-text); }
.btn.admin-logout { width: 100%; justify-content: center; border: 1px solid var(--admin-side-2); background: transparent; color: var(--admin-side-text); }
.btn.admin-logout:hover { background: var(--admin-side-2); }

.admin-content { min-width: 0; max-width: 1280px; padding: 32px 40px 48px; }
.admin-body .admin-title { margin-bottom: 20px; }
.admin-body .admin-menu a.active, .admin-body .btn-primary { --accent-fill: var(--admin-accent); }
.admin-body .btn-primary { background: var(--admin-accent); }
.admin-body .card { background: var(--surface); }

/* 後台登入頁 */
.admin-login-body { display: grid; place-items: center; background: var(--admin-side); }
.admin-login { width: 100%; padding: 24px 16px; display: grid; place-items: center; }
.admin-login-card { width: 100%; max-width: 400px; display: grid; gap: 16px; padding: 32px; border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35); }
.admin-login-card .admin-brand { padding: 0; }
.admin-login-card .admin-brand-sub { color: var(--text-muted); }
.admin-login-card h1 { margin: 4px 0 0; font-size: 1.25rem; }
.admin-login-card .alert { margin: 0; }
.admin-login-note { margin: 0; color: var(--text-muted); font-size: 0.8125rem; line-height: 1.6; }
.admin-login-note a { color: var(--admin-accent); }

@media (max-width: 900px) {
  .admin-shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .admin-sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 12px 16px; }
  .admin-menu { flex-direction: row; overflow-x: auto; order: 3; width: 100%; scrollbar-width: none; }
  .admin-menu a { white-space: nowrap; padding: 8px 10px; }
  .admin-sidebar-foot { margin: 0 0 0 auto; grid-auto-flow: column; align-items: center; padding: 0; }
  .admin-who { border-top: none; padding-top: 0; }
  .admin-who-name, .admin-side-link { display: none; }
  .btn.admin-logout { width: auto; min-height: 34px; padding: 6px 12px; }
  .admin-content { padding: 20px 16px 40px; }
}

/* 後台表格：欄位不換行，窄螢幕左右捲動 */
.admin-content .table-wrap { overflow-x: auto; }
.admin-content .table { min-width: 720px; }
.admin-content .table th, .admin-content .table td { white-space: nowrap; }
.admin-content .table td:first-child { white-space: normal; min-width: 220px; }

/* ==========================================================================
   回首頁：網站圖標都是連結，登入頁等左上角有「回首頁」
   ========================================================================== */

a.rail-brand { color: inherit; text-decoration: none; border-radius: 10px; }
a.rail-brand:hover .brand-title { text-decoration: underline; text-underline-offset: 3px; }
.rail-brand-text { display: flex; flex-direction: column; }
.rail .brand-title, .rail .brand-sub { display: block; }

.auth-home {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 10;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
}

.auth-home:hover { color: var(--text); border-color: var(--border-strong); }
.auth-mark-link { display: inline-block; border-radius: 14px; }
.auth-mark-link:hover { opacity: 0.85; }

/* 錯誤頁（找不到頁面等） */
.error-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); }
.error-card { max-width: 440px; display: grid; gap: 14px; justify-items: center; text-align: center; }
.error-code { font-family: var(--font-serif); font-size: 3rem; font-weight: 700; color: var(--brand-600); line-height: 1; }
.error-card h1 { margin: 0; font-size: 1.375rem; }
.error-card p { margin: 0; color: var(--text-secondary); line-height: 1.7; }
.error-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 6px; }
.error-actions .btn { text-decoration: none; }

@media (max-width: 900px) {
  /* 手機頂列：圖標只留圖，說明區的「網站首頁」「操作手冊」並排成圖示按鈕 */
  .rail .rail-brand-text { display: none; }
  .rail-help { flex-direction: row; gap: 2px; }
}

.site-nav > a { white-space: nowrap; }

@media (max-width: 640px) {
  .site-nav { gap: 2px; }
  .site-nav > a:not(.btn) { padding: 8px 6px; font-size: 0.875rem; }
  .site-nav .btn { padding: 6px 10px; }
}
