:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-hover: #292e36;
  --border: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --green: #3fb950;
  --green-bg: rgba(63,185,80,0.1);
  --red: #f85149;
  --red-bg: rgba(248,81,73,0.1);
  --blue: #58a6ff;
  --blue-bg: rgba(88,166,255,0.1);
  --yellow: #d29922;
  --yellow-bg: rgba(210,153,34,0.1);
  --purple: #bc8cff;
  --purple-bg: rgba(188,140,255,0.12);
  --accent: #58a6ff;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* ===================== LIGHT THEME (淺色主題) ===================== */
:root[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-tertiary: #eaeef2;
  --bg-hover: #e7ecf1;
  --border: #d0d7de;
  --text-primary: #1f2328;
  --text-secondary: #57606a;
  --text-muted: #818b98;
  --green: #1a7f37;
  --green-bg: rgba(26,127,55,0.10);
  --red: #cf222e;
  --red-bg: rgba(207,34,46,0.10);
  --blue: #0969da;
  --blue-bg: rgba(9,105,218,0.10);
  --yellow: #9a6700;
  --yellow-bg: rgba(154,103,0,0.12);
  --purple: #8250df;
  --purple-bg: rgba(130,80,223,0.12);
  --accent: #0969da;
  --shadow: 0 2px 8px rgba(140,149,159,0.25);
}

:root { color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }

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

html, body { transition: background-color 0.25s ease, color 0.25s ease; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans TC', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

/* Header */
.header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}

/* Header user avatar (頭像) — Google photoURL */
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
}
/* 頭像統一顯示於右側按鈕群（桌機與手機共用 avatar-desktop），左側頭像永遠隱藏 */
.user-avatar.avatar-mobile { display: none !important; }

.logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  margin-right: 32px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo svg { width: 24px; height: 24px; }

.nav-tabs {
  display: flex;
  gap: 4px;
  height: 100%;
  align-items: stretch;
}

.nav-tab {
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
}

.nav-tab:hover { color: var(--text-primary); background: var(--bg-hover); }
.nav-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.refresh-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}
.refresh-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.refresh-btn.spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.settings-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}
.settings-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.settings-btn.synced { border-color: var(--green); color: var(--green); }

.sync-status {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
.sync-status.success { color: var(--green); }
.sync-status.error { color: var(--red); }
.sync-status.syncing { color: var(--yellow); }

.settings-form .form-group { margin-bottom: 14px; }
.settings-form .form-group label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; }
.settings-form .form-group input {
  width: 100%; background: var(--bg-primary); border: 1px solid var(--border);
  color: var(--text-primary); padding: 10px 12px; border-radius: 6px; font-size: 14px;
  outline: none; font-family: monospace;
}
.settings-form .form-group input:focus { border-color: var(--accent); }
.settings-form .form-group .hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.sync-actions {
  display: flex; gap: 8px; margin-top: 16px; padding-top: 16px;
  border-top: 1px solid var(--border);
}
.sync-actions .btn { flex: 1; justify-content: center; }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { opacity: 0.9; }
.btn-warning { background: var(--yellow); color: #000; }
.btn-warning:hover { opacity: 0.9; }

.sync-info-box {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ---- Google login / account UI ---- */
.google-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #fff;
  color: #1f1f1f;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.google-btn:hover { background: #f1f3f4; }
.google-btn svg { width: 18px; height: 18px; }

.account-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}
.account-card .avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg-tertiary); object-fit: cover; flex-shrink: 0;
}
.account-card .meta { flex: 1; min-width: 0; }
.account-card .meta .name { font-size: 14px; color: var(--text-primary); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-card .meta .email { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.last-update { font-size: 12px; color: var(--text-muted); }
.last-update.stale { color: var(--red); }

/* Main Content */
.main { padding: 18px; max-width: 1400px; margin: 0 auto; }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Holdings two-tier sub-tabs (持倉清單第二層) */
.holdings-subheader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.sub-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
}
.sub-tab {
  padding: 7px 16px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  border-radius: 6px;
  transition: all 0.2s;
  white-space: nowrap;
}
.sub-tab:hover { color: var(--text-primary); background: var(--bg-hover); }
.sub-tab.active { color: #fff; background: var(--accent); }

.holdings-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  flex-wrap: wrap;
}

.holding-panel { display: none; }
.holding-panel.active { display: block; }

/* Total Assets big number (總資產大數字) */
.total-assets {
  background: linear-gradient(135deg, var(--bg-secondary), var(--bg-tertiary));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 12px;
}
.total-assets-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.total-assets-value {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -1px;
  color: var(--text-primary);
  line-height: 1.1;
}
@media (max-width: 768px) {
  .total-assets-value { font-size: 32px; }
}

/* 總資產卡片內：四類資產水平長條圖 */
.asset-breakdown {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.asset-breakdown:empty { display: none; }
.ab-row { display: flex; flex-direction: column; gap: 5px; }
.ab-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}
.ab-name { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.ab-dot { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }
.ab-val { display: flex; align-items: baseline; gap: 8px; }
.ab-pct { font-weight: 700; color: var(--text-primary); }
.ab-val .amt { color: var(--text-secondary); font-size: 12px; }
.ab-track {
  width: 100%;
  height: 7px;
  border-radius: 4px;
  background: var(--bg-tertiary);
  overflow: hidden;
}
.ab-fill { height: 100%; border-radius: 4px; transition: width 0.3s ease; }

/* Dashboard Summary Cards (三張指標卡片) */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.summary-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.summary-card-title {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.summary-card-main {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.summary-card-sub {
  font-size: 14px;
  margin-top: 6px;
  font-weight: 500;
  color: var(--text-secondary);
}

.summary-card-main.positive, .summary-card-sub.positive { color: var(--green); }
.summary-card-main.negative, .summary-card-sub.negative { color: var(--red); }

@media (max-width: 768px) {
  .summary-cards { grid-template-columns: 1fr 1fr; }
  /* 2 + 1: the third card spans the full width on its own row */
  .summary-cards .summary-card:nth-child(3) { grid-column: 1 / -1; }
}

/* Dashboard Overview Cards */
.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.overview-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.overview-card .label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.overview-card .value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.overview-card .change {
  font-size: 14px;
  margin-top: 4px;
  font-weight: 500;
}

.positive { color: var(--green); }
.negative { color: var(--red); }
.neutral { color: var(--text-secondary); }

/* Section */
.section {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}

.section-header {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.section-title {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title .badge {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 400;
}

/* Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-tertiary);
  position: sticky;
  top: 0;
}

.data-table th.right, .data-table td.right { text-align: right; }

.data-table td {
  padding: 9px 14px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.data-table tr:hover td { background: var(--bg-hover); }
.data-table tr:last-child td { border-bottom: none; }

.symbol-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left; /* 標的簡稱與全名一律靠左（避免手機卡片 text-align:right 讓短代號如 GRAB 偏右） */
}

.symbol-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}

.symbol-icon.us { background: var(--blue-bg); color: var(--blue); }
.symbol-icon.tw { background: var(--green-bg); color: var(--green); }
.symbol-icon.crypto { background: var(--yellow-bg); color: var(--yellow); }

.symbol-name { font-weight: 600; font-size: 14px; }
.symbol-full { font-size: 12px; color: var(--text-secondary); }

.price-flash { animation: flash 0.5s; }
@keyframes flash { 0%,100% { background: transparent; } 50% { background: rgba(88,166,255,0.1); } }

.pnl-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
}
.pnl-pill.positive { background: var(--green-bg); }
.pnl-pill.negative { background: var(--red-bg); }

/* Add Form */
.add-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.add-bar input, .add-bar select {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

.add-bar input:focus, .add-bar select:focus {
  border-color: var(--accent);
}

.add-bar input::placeholder { color: var(--text-muted); }

.add-bar .input-symbol { width: 120px; }
.add-bar .input-price { width: 120px; }
.add-bar .input-qty { width: 100px; }

.btn {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { opacity: 0.9; }

.btn-danger {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  padding: 4px 8px;
  font-size: 12px;
}
.btn-danger:hover { background: var(--red-bg); color: var(--red); border-color: var(--red); }

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* Empty State */
.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 14px; }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.show { display: flex; }

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 440px;
  max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.modal h3 {
  font-size: 18px;
  margin-bottom: 16px;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input, .form-group select {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
}

.form-group input:focus, .form-group select:focus {
  border-color: var(--accent);
}

/* 日期欄位在 iOS/WebKit 有內建外觀與最小寬度，會超出 Modal 邊界——強制與其他欄位同寬 */
.form-group input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  min-width: 0;
  max-width: 100%;
  min-height: 41px;
  color-scheme: dark;
}
.form-group input[type="date"]::-webkit-date-and-time-value { text-align: left; }
:root[data-theme="light"] .form-group input[type="date"] { color-scheme: light; }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-hover); }

/* Watchlist quick add */
.watchlist-add {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  align-items: center;
}
.watchlist-add input,
.watchlist-add select {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 0 12px;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  height: 36px;
  transition: border-color 0.2s;
}
.watchlist-add input:focus,
.watchlist-add select:focus { border-color: var(--accent); }
.watchlist-add input::placeholder { color: var(--text-muted); }
.watchlist-add .btn { height: 36px; }

/* 價格警示動作按鈕群（桌面：與表單同列） */
.alert-actions { display: flex; gap: 8px; align-items: center; }

/* 交易紀錄標題列動作按鈕群 */
.header-actions { display: flex; gap: 8px; align-items: center; }
.header-actions .lbl-short { display: none; }

/* ---- Symbol autocomplete dropdown ---- */
.ac-wrap {
  position: relative;
  flex: 1;
  max-width: 320px;
}
.ac-wrap input { width: 100%; }
.ac-list {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 250;
  max-height: 280px;
  overflow-y: auto;
}
.ac-list.show { display: block; }
.ac-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.active { background: var(--bg-hover); }
.ac-item .ac-sym { font-weight: 700; color: var(--text-primary); }
.ac-item .ac-name {
  flex: 1; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ac-item .ac-exch {
  font-size: 11px; color: var(--text-muted);
  background: var(--bg-tertiary); padding: 1px 6px; border-radius: 4px;
  flex-shrink: 0;
}
.ac-loading, .ac-empty {
  padding: 10px 12px; font-size: 12px; color: var(--text-muted);
}

/* Status Indicator */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.status-dot.online { background: var(--green); }
.status-dot.offline { background: var(--red); }

/* Allocation bar */
.alloc-bar {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg-tertiary);
  margin-top: 12px;
}
.alloc-bar div { height: 100%; transition: width 0.3s; }
.alloc-bar .us-seg { background: var(--blue); }
.alloc-bar .tw-seg { background: var(--green); }
.alloc-bar .crypto-seg { background: var(--yellow); }
.alloc-bar .cash-seg { background: var(--purple); }

/* Cash currency pill */
.cash-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  background: var(--purple-bg);
  color: var(--purple);
}

/* 現金「可加碼資金」三幣別橫條圖 */
.cash-bar {
  display: flex;
  width: 100%;
  height: 26px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-tertiary);
  margin-top: 6px;
}
.cash-bar .seg {
  height: 100%;
  min-width: 2px;
  transition: width 0.3s ease;
  cursor: default;
}
.cash-bar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 10px;
}
.cash-bar-legend .lg {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}
.cash-bar-legend .dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* 看盤 Watchlist 卡片（細線 border、輕陰影、可展開） */
.watch-cards { display: flex; flex-direction: column; gap: 10px; }
.watch-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: transparent;
  transition: box-shadow 0.18s ease, border-color 0.18s ease;
}
.watch-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.16);
}
.watch-main {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
}
.watch-price {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.watch-price .wp-price { font-weight: 600; font-size: 15px; }
.watch-expand {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
  transition: transform 0.2s ease, color 0.2s ease;
}
.watch-card:hover .watch-expand { color: var(--text-secondary); }
.watch-card.expanded .watch-expand { transform: rotate(180deg); color: var(--accent); }
.watch-detail {
  display: none;
  padding: 0 14px 12px;
  border-top: 1px solid var(--border);
}
.watch-card.expanded .watch-detail { display: block; }
.wd-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 16px;
  padding: 12px 0;
}
.wd-item {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}
.wd-item span { color: var(--text-muted); }
.wd-item b { font-weight: 600; }
.wd-actions { display: flex; justify-content: flex-end; }

.alloc-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}
.alloc-legend span { display: flex; align-items: center; gap: 4px; }
.legend-dot { width: 8px; height: 8px; border-radius: 2px; }

/* Responsive */
@media (max-width: 768px) {
  /* item 15｜頂部工具列：App 名稱靠左；右側 頭像/鈴鐺/隱私/主題/更新 */
  .header { padding: 0 12px; height: 52px; gap: 8px; flex-wrap: nowrap; }
  .logo { margin: 0; flex: 1; min-width: 0; justify-content: flex-start; font-size: 16px; overflow: hidden; white-space: nowrap; }
  .header-right { margin-left: auto; gap: 8px; flex-wrap: nowrap; }
  #settingsBtn { display: none; }
  /* 更新報價按鈕在手機收成純 icon */
  #refreshBtn .btn-text { display: none; }
  #refreshBtn { padding: 6px; }
  .header-right .icon-btn svg,
  .header-right .refresh-btn svg { width: 21px; height: 21px; }

  .nav-tabs { width: 100%; overflow-x: auto; padding-bottom: 4px; }
  .nav-tabs::-webkit-scrollbar { height: 0px; }
  .nav-tab { padding: 0 12px; font-size: 14px; flex-shrink: 0; }
  .main { padding: 10px; }
  .overview-grid { grid-template-columns: 1fr; }

  /* Table overflow handling */
  div[id$="Body"] { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .data-table { min-width: 600px; font-size: 13px; }
  .data-table th, .data-table td { padding: 10px 8px; }

  .add-bar { flex-direction: column; }
  .add-bar input, .add-bar select { width: 100% !important; }

  /* 3｜看盤加入列：輸入框與「＋」按鈕同一列，輸入框撐滿、按鈕縮至字元寬 */
  .watchlist-add { flex-direction: row; align-items: center; }
  .watchlist-add .ac-wrap { max-width: none; flex: 1; min-width: 0; }
  .watchlist-add input { width: 100% !important; }
  .watchlist-add > button { flex: 0 0 auto; width: auto; padding: 8px 14px; font-size: 16px; line-height: 1; }

  /* 13｜交易紀錄：標題列按鈕縮短文字 */
  .header-actions .lbl-full { display: none; }
  .header-actions .lbl-short { display: inline; }

  /* 8｜價格警示表單：兩欄網格整齊排列
     row1: 市場 | 條件, row2: 標的（滿版）, row3: 目標價（滿版）, row4: 動作按鈕 */
  .alert-form.watchlist-add {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-items: stretch;
  }
  .alert-form #alertMarket { grid-row: 1; grid-column: 1; min-width: 0; width: 100% !important; }
  .alert-form #alertCondition { grid-row: 1; grid-column: 2; min-width: 0; width: 100% !important; }
  .alert-form .ac-wrap { grid-row: 2; grid-column: 1 / -1; max-width: none; min-width: 0; width: 100%; }
  .alert-form #alertPrice { grid-row: 3; grid-column: 1 / -1; min-width: 0; width: 100% !important; }
  .alert-form .alert-actions {
    grid-row: 4;
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }
  .alert-form .alert-actions .alert-add { grid-column: 1 / -1; }
  .alert-form .alert-actions button { width: auto; align-self: stretch; }

  .modal { width: 95vw; padding: 20px; }
}

/* ===================== MOBILE BOTTOM NAV + FAB (手機底部導覽 + 浮動按鈕) ===================== */
.mobile-bottom-nav { display: none; }
.fab-btn { display: none; }

.mobile-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 60px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  z-index: 150;
  align-items: stretch;
  justify-content: space-around;
}

.mbn-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 9px;
  font-weight: 500;
  white-space: nowrap;
  transition: color 0.2s;
}
.mbn-item svg { width: 22px; height: 22px; }
.mbn-item.active { color: var(--accent); }

.fab-btn {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  z-index: 160;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  transition: transform 0.15s, opacity 0.2s;
}
.fab-btn:hover { opacity: 0.92; }
.fab-btn:active { transform: scale(0.92); }
.fab-btn svg { width: 26px; height: 26px; }

/* 「更多」展開表（手機）：目標配置 + 更新 / 隱私 / 主題 / 設定 */
.more-sheet { display: none; }
.more-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 20px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 15px;
  cursor: pointer;
  text-align: left;
}
.more-item:last-child { border-bottom: none; }
.more-item:hover { background: var(--bg-hover); }
.more-item svg { width: 20px; height: 20px; color: var(--text-secondary); flex-shrink: 0; }

@media (max-width: 768px) {
  .mobile-bottom-nav { display: flex; }
  .fab-btn { display: flex; }
  body { padding-bottom: 70px; }
  /* tab 切換改由底部 nav 控制，隱藏頂部 tab bar */
  .nav-tabs { display: none; }

  /* 「更多」展開：浮動清單顯示在底部 nav 上方 */
  body.more-open .more-sheet {
    display: flex;
    flex-direction: column;
    position: fixed;
    bottom: 60px;
    left: 0;
    width: 100%;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    box-shadow: 0 -8px 24px rgba(0,0,0,0.4);
    z-index: 155;
  }
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease;
  max-width: 320px;
}
@keyframes slideIn { from { transform: translateX(100%); opacity:0; } to { transform: translateX(0); opacity:1; } }

.loading-shimmer {
  background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-hover) 50%, var(--bg-tertiary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
  height: 16px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.price-stale {
  color: var(--text-muted) !important;
  font-weight: 400 !important;
}
.price-stale-badge {
  font-size: 11px;
  color: var(--yellow);
  margin-left: 4px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border); }

/* Action buttons for holdings rows */
.btn-edit {
  background: transparent; color: var(--text-muted); border: 1px solid transparent;
  padding: 4px 8px; font-size: 12px;
}
.btn-edit:hover { background: var(--blue-bg); color: var(--blue); border-color: var(--blue); }

.btn-sell {
  background: transparent; color: var(--text-muted); border: 1px solid transparent;
  padding: 4px 8px; font-size: 12px;
}
.btn-sell:hover { background: var(--yellow-bg); color: var(--yellow); border-color: var(--yellow); }

.btn-buy {
  background: transparent; color: var(--text-muted); border: 1px solid transparent;
  padding: 4px 8px; font-size: 12px;
}
.btn-buy:hover { background: var(--green-bg); color: var(--green); border-color: var(--green); }

/* Transaction type badges */
.tx-badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 600;
}
.tx-badge.buy { background: var(--green-bg); color: var(--green); }
.tx-badge.sell { background: var(--red-bg); color: var(--red); }
.tx-badge.dividend { background: var(--yellow-bg); color: var(--yellow); }

/* 市值欄：美股市值 + 台幣換算上下堆疊 */
.mv-stack {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.35;
}
.mv-twd { display: block; color: var(--text-muted); font-size: 12px; font-weight: 400; }

/* 交易紀錄時間過濾列 */
.tx-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-bottom: 16px;
}
.tx-range-toggle { display: flex; flex-wrap: wrap; gap: 6px; }
.tx-custom-range { display: flex; align-items: center; gap: 6px; }
.tx-custom-range input[type="date"] {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 5px 8px;
  border-radius: var(--radius);
  font-size: 12px;
  color-scheme: dark;
}
.tx-range-sep { color: var(--text-muted); font-size: 12px; }

/* 現金連動市場複選（Modal 內） */
.cash-link-options { display: flex; flex-wrap: wrap; gap: 8px 20px; padding: 4px 0; }
.form-group .cash-link-opt {
  display: flex; align-items: center; gap: 6px;
  font-size: 14px; color: var(--text-primary); cursor: pointer; margin: 0;
}
.form-group .cash-link-opt input[type="checkbox"] {
  width: auto; padding: 0; margin: 0;
  accent-color: var(--accent); cursor: pointer;
}

/* 現金帳戶連動市場標籤 */
.cash-link-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  background: var(--blue-bg);
  color: var(--blue);
  border: 1px solid var(--blue);
  vertical-align: middle;
  white-space: nowrap;
}

/* Exchange rate */
.exchange-rate-badge {
  font-size: 12px; color: var(--text-muted);
  background: var(--bg-tertiary); padding: 2px 8px; border-radius: 4px;
}

/* Chart container */
.chart-container {
  position: relative;
}

/* Net worth chart time range selector (時間範圍切換) */
.chart-range-selector {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  padding: 12px 16px 0;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.range-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 5px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.range-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.range-btn.active {
  background: var(--blue-bg);
  border-color: var(--accent);
  color: var(--accent);
}

/* ===================== Feature Enhancements (Section 2) ===================== */

/* Market status badge */
.mkt-status {
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 10px; margin-left: 6px;
  vertical-align: middle; white-space: nowrap;
}
.mkt-status.open   { color: var(--green);  background: var(--green-bg); }
.mkt-status.pre    { color: var(--blue);   background: var(--blue-bg); }
.mkt-status.post   { color: var(--yellow); background: var(--yellow-bg); }
.mkt-status.closed { color: var(--text-muted); background: var(--bg-tertiary); }

/* Fear & Greed badge */
.fg-badge {
  display: inline-block; font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: 12px;
}
.fg-badge.fg-efear   { color: #fff; background: var(--red); }
.fg-badge.fg-fear    { color: var(--red);    background: var(--red-bg); }
.fg-badge.fg-neutral { color: var(--text-muted); background: var(--bg-tertiary); }
.fg-badge.fg-greed   { color: var(--green);  background: var(--green-bg); }
.fg-badge.fg-egreed  { color: #fff; background: var(--green); }
.fg-src { font-size: 11px; color: var(--text-muted); margin-left: 6px; }

/* 恐懼貪婪指數半圓 Gauge */
.fg-gauge {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 260px;
  margin: 0 auto 6px;
}
.fg-gauge-svg { width: 100%; height: auto; display: block; }
.fg-gauge-val { fill: var(--text-primary); font-size: 28px; font-weight: 700; }
.fg-gauge-label { font-size: 15px; font-weight: 700; margin-top: -6px; }

/* ===================== UI/UX ENHANCEMENTS (Section 3) ===================== */

/* ---- Header icon buttons (theme / privacy) ---- */
.icon-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 34px; height: 34px;
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn.active { border-color: var(--accent); color: var(--accent); }

/* ---- Privacy mode (隱私模式) ---- */
body.privacy-on .amt,
body.privacy-on .overview-card .value,
body.privacy-on .overview-card .change,
body.privacy-on .summary-card-main,
body.privacy-on .summary-card-sub,
body.privacy-on .total-assets-value,
body.privacy-on #netWorthChart,
body.privacy-on #allocDonut {
  filter: blur(7px);
  transition: filter 0.15s ease;
  user-select: none;
  pointer-events: none;
}

/* ---- Sortable table headers (表格排序) ---- */
.data-table th.sortable { cursor: pointer; user-select: none; transition: color 0.15s; }
.data-table th.sortable:hover { color: var(--text-secondary); }
.data-table th.sortable .sort-ind { margin-left: 4px; font-size: 9px; opacity: 0.35; }
.data-table th.sortable.sorted { color: var(--accent); }
.data-table th.sortable.sorted .sort-ind { opacity: 1; }

/* ---- Number rolling animation (數字變化動畫) ---- */
.value.num-bump { animation: numBump 0.45s ease; }
@keyframes numBump { 0% { transform: scale(1); } 35% { transform: scale(1.05); } 100% { transform: scale(1); } }

/* ---- Undo toast (復原) ---- */
.toast.toast-undo { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.toast .toast-msg { flex: 1; }
.toast .toast-undo-btn {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.toast .toast-undo-btn:hover { background: var(--blue-bg); }

/* ---- Empty-state onboarding (空狀態引導) ---- */
.empty-onboard { text-align: center; padding: 28px 16px; color: var(--text-muted); }
.empty-onboard .eo-title { font-size: 14px; margin-bottom: 4px; }
.empty-onboard .eo-sub { font-size: 12px; margin-bottom: 14px; }
.empty-onboard .eo-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--blue-bg); color: var(--accent);
  border: 1px solid var(--accent);
  padding: 7px 16px; border-radius: 6px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all 0.2s;
}
.empty-onboard .eo-btn:hover { background: var(--accent); color: #fff; }

/* ---- Relative "updated X ago" ---- */
.last-update .rel-time { color: var(--text-muted); }

/* ===================== MOBILE CARD LAYOUT (手機體驗) ===================== */
/* ---- App footer / copyright ---- */
.app-footer {
  margin-top: 32px;
  padding: 20px 16px 28px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.footer-sep { margin: 0 8px; color: var(--border); }
.footer-donate-link {
  background: none;
  border: none;
  padding: 0;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s;
}
.footer-donate-link:hover { color: var(--accent); text-decoration: underline; }
.footer-donate-link .donate-heart { width: 12px; height: 12px; vertical-align: -1px; margin-right: 3px; }

/* ===================== 贊助 Modal（支持這個專案） ===================== */
/* 純色幾何圖示，沿用網站單色 currentColor 風格 */
.donate-heart { width: 1em; height: 1em; fill: currentColor; vertical-align: -0.14em; }
.modal h3 .donate-heart { width: 18px; height: 18px; color: var(--accent); vertical-align: -2px; margin-right: 2px; }
.donate-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}
.donate-card {
  display: block;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-decoration: none;
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.donate-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  transform: translateY(-1px);
}
.donate-card.disabled {
  cursor: default;
  opacity: 0.55;
  pointer-events: none;
}
.donate-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.donate-card-title { font-weight: 600; font-size: 14px; flex: 1; }
.donate-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--blue-bg);
  color: var(--blue);
  white-space: nowrap;
}
.donate-badge.soon { background: var(--bg-tertiary); color: var(--text-muted); }
.donate-card-desc { font-size: 12px; color: var(--text-secondary); }
.donate-intro {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
}
.donate-contact {
  margin-top: 12px;
  text-align: center;
}
.donate-contact-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.15s;
}
.donate-contact-link:hover { color: var(--accent); }
.donate-contact-link svg { width: 16px; height: 16px; flex-shrink: 0; }
.donate-note {
  margin-top: 12px;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
}

@media (max-width: 640px) {
  table.cards-mobile { min-width: 0 !important; }
  table.cards-mobile thead { display: none; }
  table.cards-mobile, table.cards-mobile tbody, table.cards-mobile tr, table.cards-mobile td { display: block; width: 100%; }
  table.cards-mobile tr {
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: var(--bg-secondary);
  }
  table.cards-mobile tr:hover td { background: transparent; }
  table.cards-mobile td {
    border: none !important;
    padding: 6px 2px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: right;
    font-size: 13px;
  }
  table.cards-mobile td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    text-align: left;
    margin-right: 12px;
    flex-shrink: 0;
  }
  table.cards-mobile td.cell-symbol {
    justify-content: flex-start;
    text-align: left;
    border-bottom: 1px solid var(--border) !important;
    padding-bottom: 10px;
    margin-bottom: 4px;
  }
  table.cards-mobile td.cell-symbol::before { content: ""; margin: 0; }
  table.cards-mobile td.cell-actions { justify-content: flex-end; gap: 6px; padding-top: 8px; }
  table.cards-mobile td.cell-actions::before { content: ""; margin: 0; }
  table.cards-mobile td:empty { display: none; }
  /* keep the empty-state / onboarding row full width, not a label/value split */
  table.cards-mobile td[colspan]::before { content: ""; margin: 0; }
  table.cards-mobile td[colspan] { justify-content: center; text-align: center; }

  /* 持倉卡片：主要數字加大、名稱微加大、padding 與 gap 縮小 */
  table.cards-mobile.holdings-cards tr { padding: 6px 10px; margin-bottom: 10px; }
  table.cards-mobile.holdings-cards td { padding: 4px 2px; font-size: 15px; }
  table.cards-mobile.holdings-cards td::before { font-size: 11px; }
  table.cards-mobile.holdings-cards .symbol-name { font-size: 15px; }
}

/* ===================== 離線唯讀模式（雲端權威架構） ===================== */
/* 登入且離線時：資料以雲端為準，本機僅為唯讀快取 → 顯示 banner、鎖定編輯 UI */
#offlineBanner {
  position: sticky;
  top: 0;
  z-index: 3000;
  padding: 8px 14px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(90deg, #b45309, #d97706);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

/* 唯讀模式下淡化編輯類按鈕（點擊仍會由 requireEditable() 攔下並提示） */
body.cloud-readonly .btn-primary,
body.cloud-readonly .btn-danger,
body.cloud-readonly .action-btn,
body.cloud-readonly .toast-undo-btn {
  opacity: 0.45;
  filter: grayscale(0.4);
}
