/* ==========================================================================
   平衡豬 — 設計系統「存股帳本」
   米白紙色底、墨綠黑側欄、一個深青綠主色；台股慣例紅漲綠跌。
   股票深藍、債券土黃，明度差距大，色弱也分得出來。
   全站只用一組系統字型（Mac 蘋方＋San Francisco、Windows 微軟正黑體＋Segoe UI），標題與內文同一種字，
   靠粗細與大小分層級；不另外下載字型，PWA 離線時也不會退字。
   ========================================================================== */

: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;

  /* 英數字放前面：蘋方的數字不支援等寬（tabular-nums），交給 San Francisco／Segoe UI，持股表才對得齊 */
  --font: -apple-system, BlinkMacSystemFont, 'PingFang TC', 'Segoe UI', 'Microsoft JhengHei', 'Noto Sans TC', sans-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);
  font-family: inherit;
  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;
  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; }
}

/* ==========================================================================
   再平衡計算結果（全新卡片式結構）
   ========================================================================== */

.rebalance-result-wrap {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.rebalance-mode-banner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-inset);
}

.rebalance-mode-banner.is-smart {
  border-color: rgba(43, 106, 69, 0.25);
  background: rgba(43, 106, 69, 0.05);
}

.rebalance-mode-banner.is-forced {
  border-color: rgba(138, 79, 6, 0.25);
  background: rgba(138, 79, 6, 0.05);
}

.rebalance-mode-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.rebalance-mode-banner.is-smart .rebalance-mode-icon {
  color: var(--sell);
}

.rebalance-mode-banner.is-forced .rebalance-mode-icon {
  color: var(--warning);
}

.rebalance-mode-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.rebalance-mode-title {
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--text);
}

.rebalance-mode-pill {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: var(--radius-full);
}

.rebalance-mode-banner.is-smart .rebalance-mode-pill {
  background: var(--sell-bg);
  color: var(--sell);
}

.rebalance-mode-banner.is-forced .rebalance-mode-pill {
  background: var(--warning-bg);
  color: var(--warning);
}

.rebalance-mode-sub {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-top: 3px;
  line-height: 1.45;
}

.rebalance-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.rebalance-kpi-card {
  padding: 12px 14px;
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.rebalance-kpi-card .kpi-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.rebalance-kpi-card .kpi-val {
  font-size: 1.25rem;
  font-weight: 800;
  margin: 4px 0 2px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.rebalance-kpi-card .kpi-sub {
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.rebalance-kpi-card.is-boost {
  border-color: rgba(245, 158, 11, 0.3);
  background: rgba(245, 158, 11, 0.05);
}

.rebalance-kpi-card.is-boost .kpi-val {
  color: var(--brand-500);
}

.order-actions-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 4px;
}

.order-actions-head h3 {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.order-actions-tally {
  display: flex;
  gap: 6px;
}

.order-tally {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: var(--radius-full);
}

.order-tally.is-buy { background: var(--buy-bg); color: var(--buy); }
.order-tally.is-sell { background: var(--sell-bg); color: var(--sell); }

.order-actions-hint {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: -8px;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

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

.order-actions-hint strong { color: var(--text); }

/* 委託單：左側色條與買賣標籤一眼分出買 / 賣，編號就是下單順序 */
.order-ticket-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.order-ticket {
  --side: var(--buy);
  --side-bg: var(--buy-bg);
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--side);
  border-radius: var(--radius);
  overflow: hidden;
  transition: opacity var(--transition), border-color var(--transition);
}

.order-ticket.is-sell {
  --side: var(--sell);
  --side-bg: var(--sell-bg);
}

.order-ticket-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--side-bg);
  border-bottom: 1px solid var(--border);
}

.order-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--surface);
  border: 1px solid var(--side);
  color: var(--side);
  font-size: 0.75rem;
  font-weight: 800;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.order-side {
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  background: var(--side);
  color: var(--surface);
  font-size: 0.8125rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  flex-shrink: 0;
}

.order-ident {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.order-ticker {
  font-weight: 800;
  font-size: 1rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.order-name {
  font-size: 0.875rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.order-done {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-full);
  background: var(--surface);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  user-select: none;
}

.order-done input {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--side);
  cursor: pointer;
}

.order-ticket.is-done { opacity: 0.55; }
.order-ticket.is-done .order-done { color: var(--side); border-color: var(--side); }
.order-ticket.is-done .order-field-val { text-decoration: line-through; text-decoration-thickness: 1px; }

.order-ticket-body {
  display: grid;
  grid-template-columns: 1.35fr 1fr 1.25fr 1.3fr;
}

.order-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px 12px;
  min-width: 0;
}

.order-field + .order-field { border-left: 1px dashed var(--border); }

.order-field-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.order-field-val {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.order-field-val small {
  margin-left: 3px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}

.order-field-qty .order-field-val {
  font-size: 1.375rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--side);
}

.order-field-sub {
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.order-splits {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}

.order-split {
  font-size: 0.6875rem;
  padding: 1px 7px;
  border-radius: var(--radius-sm);
  background: var(--surface-inset);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
}

.order-split b { color: var(--text); }

.order-ratio-val {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.875rem;
}

.order-ratio-val span { color: var(--text-muted); font-weight: 400; }

.order-ratio-bar {
  position: relative;
  height: 6px;
  margin-top: 6px;
  border-radius: var(--radius-full);
  background: var(--surface-inset);
  border: 1px solid var(--border);
}

.order-ratio-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: var(--radius-full);
  background: var(--side);
  opacity: 0.6;
}

.order-ratio-target {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2px;
  margin-left: -1px;
  background: var(--text);
  border-radius: 1px;
}

.order-empty-card {
  padding: 24px;
  text-align: center;
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.order-empty-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

.order-empty-sub {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.at-target-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.calc-details-collapse {
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 0.75rem;
}

.calc-details-collapse summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
  list-style: none;
}

.calc-details-collapse summary::-webkit-details-marker {
  display: none;
}

.calc-details-collapse[open] summary {
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
}

.calc-details-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--text-muted);
  font-family: monospace;
  font-size: 0.75rem;
  line-height: 1.5;
}

/* 平板：四欄太擠，改成 2 × 2 */
@media (max-width: 720px) {
  .order-ticket-body { grid-template-columns: 1fr 1fr; }
  .order-field:nth-child(3) { border-left: none; }
  .order-field:nth-child(n + 3) { border-top: 1px dashed var(--border); }
}

@media (max-width: 640px) {
  /* KPI 收緊間距，讓下單清單早點出現在畫面上 */
  .rebalance-kpi-grid { grid-template-columns: 1fr; gap: 8px; }
  .rebalance-kpi-card { padding: 10px 12px; }
  .rebalance-kpi-card .kpi-val { font-size: 1.125rem; margin: 2px 0 1px; }

  /* 名稱換到代號下一行，「已委託」留足手指點按的大小 */
  .order-ticket-head { flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
  .order-ident { flex-direction: column; align-items: flex-start; gap: 0; }
  .order-name { max-width: 100%; font-size: 0.8125rem; }
  .order-done { padding: 8px 12px; min-height: 36px; }
  .order-field { padding: 9px 12px 10px; }

  /* 數量最重要，獨佔一整列 */
  .order-ticket-body { grid-template-columns: 1fr 1fr 1fr; }
  .order-field-qty {
    grid-column: 1 / -1;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: baseline;
    column-gap: 10px;
    border-bottom: 1px dashed var(--border);
  }
  .order-field-qty .order-field-label { flex-basis: 100%; }
  .order-field:nth-child(n + 2) { border-top: none; }
  .order-field:nth-child(2) { border-left: none; }
  .order-field:nth-child(3) { border-left: 1px dashed var(--border); }
  .order-field-val { font-size: 0.9375rem; }
}

/* 小手機：參考價與應付並排，佔比獨佔一列 */
@media (max-width: 420px) {
  .order-ticket-body { grid-template-columns: 1fr 1fr; }
  .order-field-ratio {
    grid-column: 1 / -1;
    border-left: none !important;
    border-top: 1px dashed var(--border) !important;
  }
  .order-field-qty .order-field-val { font-size: 1.25rem; }
}

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

.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); }

/* 頁面上方可關閉的通知（例如更新股價的結果） */
.page-notice { align-items: flex-start; }
.page-notice-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.page-notice-close { flex-shrink: 0; margin: -4px -6px -4px 0; color: inherit; }

.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-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-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;
  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) 180px;
  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;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 4px 10px;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

/* 「實際 / 目標」不拆成兩行；放不下時偏差標籤整個換到下一行 */
.alloc-figures > span:first-child { white-space: nowrap; }

.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; }

/* 左右內距 8px：表格在 1280px 左右的筆電上已經接近放不下，內距小一點，最右邊的編輯、刪除比較不會被切到 */
.holdings-table th { padding: 14px 8px; background: transparent; font-size: 0.78rem; }
.holdings-table td { padding: 14px 8px; }

.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); }

/* ==========================================================================
   存股帳本：數字卡片（合併檢視、記帳）
   ========================================================================== */

.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; }


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

.overlay { background: rgba(23, 33, 30, 0.55); }
.modal { border-radius: 18px; }
.modal-head h2 { 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; }

/* 欄位檢核：錯誤直接標在欄位上（紅框 + 下方說明） */
.input.is-invalid,
.input.is-invalid:hover:not(:disabled) { border-color: var(--danger); }
.input.is-invalid:focus { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(163, 38, 29, 0.18); }

.field-error {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--danger);
}

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

.monthly-grid-cell:has(.is-invalid) { border-color: var(--danger); background: var(--danger-bg); }
/* 月份格很窄：紅框在整格上，說明只留短字、不放圖示 */
.monthly-grid-cell .input.is-invalid:focus { box-shadow: none; }
.monthly-grid-cell .field-error svg { display: none; }
.month-chip-row.is-invalid .month-chip:not(.active) { border-color: var(--danger); }
/* 單期金額的錯誤放到整列最下面，不要把按鈕擠開 */
.dividend-preset-input-row .field-error { flex-basis: 100%; order: 1; }

.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-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 { 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; }
}

@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; }

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

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

/* 市價說明：每天收盤後自動更新的收盤日、停住沒更新的代號；試用模式提醒自己填 */
.price-status { flex-basis: 100%; font-size: 0.8125rem; color: var(--text-muted); line-height: 1.6; }
.price-status svg { vertical-align: -2px; }
.price-status a { color: var(--brand-600); }
/* 自己輸入的市價（例如限價）：和自動更新的收盤價區分，下一個收盤價出來後恢復自動 */
.price-manual-note { color: var(--warning); font-weight: 600; }
.link-btn.cell-note { color: var(--brand-500); font-size: 0.75rem; }
.input[readonly] { background: var(--surface-inset); color: var(--text-secondary); cursor: default; }

.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-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-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-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-links a.site-footer-yt { display: inline-flex; align-items: center; gap: 6px; }
.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-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; }

/* 介紹頁的股債平衡迷你試算（/js/landing.js） */
.balance-quick { transition: opacity var(--transition); }
.balance-quick.is-busy .bq-actions { opacity: 0.55; }
.bq-mode { background: var(--brand-100); color: var(--brand-600); }
.bq-mode.is-forced { background: var(--warning-bg); color: var(--warning); }
.bq-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.bq-fields .field { gap: 4px; }
.bq-fields .label { font-size: 0.75rem; }
.bq-target { display: grid; gap: 6px; }
.bq-range { width: 100%; accent-color: var(--brand-500); }
.bq-bar-row { display: grid; grid-template-columns: 3.5em minmax(0, 1fr) 6.5em; align-items: center; gap: 10px; font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.bq-bar-row strong { text-align: right; font-size: 0.9375rem; }
.bq-bar-label { color: var(--text-muted); }
.bq-actions { display: grid; gap: 10px; transition: opacity var(--transition); }
.bq-actions .landing-demo-row strong { min-width: 88px; }
.bq-note { margin: 0; color: var(--text-secondary); font-size: 0.8125rem; line-height: 1.6; }
.bq-error { color: var(--danger); }
.balance-quick .landing-demo-foot a { color: var(--brand-600); font-weight: 600; text-decoration: none; white-space: nowrap; }
.balance-quick .landing-demo-foot a:hover { text-decoration: underline; }

@media (max-width: 420px) {
  .bq-fields { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .bq-fields .field:last-child { grid-column: 1 / -1; }
  .balance-quick .landing-demo-foot { flex-direction: column; gap: 6px; }
}

.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-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; }

/* 介紹頁「最新文章與影片」：深綠色的醒目區塊，左邊主打最新影片，右邊是其他最新文章（兩種主題都用同一組深色） */
.landing-latest {
  position: relative;
  display: grid;
  gap: 24px;
  margin: 0 0 40px;
  padding: 32px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 24px;
  background:
    radial-gradient(90% 120% at 100% 0%, rgba(111, 191, 180, 0.35) 0%, transparent 60%),
    radial-gradient(60% 80% at 0% 100%, rgba(227, 51, 51, 0.16) 0%, transparent 60%),
    linear-gradient(135deg, #17463f 0%, #0f2a27 100%);
  color: #f2f7f6;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.landing-latest a { color: inherit; text-decoration: none; }
.landing-latest a:focus-visible { outline: 3px solid #8fd0c7; outline-offset: 3px; }
.landing-latest-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }

.landing-latest-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.1);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.landing-latest-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff5a4f;
  box-shadow: 0 0 0 0 rgba(255, 90, 79, 0.6);
  animation: landing-latest-pulse 2s ease-out infinite;
}

@keyframes landing-latest-pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 90, 79, 0.6); }
  70%, 100% { box-shadow: 0 0 0 8px rgba(255, 90, 79, 0); }
}

.landing-latest-title { margin: 12px 0 6px; color: #fff; font-size: clamp(1.5rem, 3vw, 2rem); font-weight: 700; line-height: 1.3; }
.landing-latest-lead { max-width: 560px; margin: 0; color: rgba(242, 247, 246, 0.76); font-size: 0.9375rem; line-height: 1.7; }

.landing-latest-all {
  flex-shrink: 0;
  padding: 9px 18px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: var(--radius-full);
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition);
}

.landing-latest-all:hover { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.6); }
.landing-latest-links { display: flex; flex-wrap: wrap; gap: 10px; }
.landing-latest-yt { display: inline-flex; align-items: center; gap: 8px; }
.landing-latest-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 20px; }

.landing-latest-feature {
  display: grid;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
  transition: transform var(--transition), border-color var(--transition), background var(--transition);
}

.landing-latest-feature:hover { transform: translateY(-3px); border-color: rgba(143, 208, 199, 0.6); background: rgba(255, 255, 255, 0.09); }
.landing-latest-thumb { position: relative; aspect-ratio: 16 / 9; background: #000; overflow: hidden; }
.landing-latest-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform 0.4s ease; }
.landing-latest-feature:hover .landing-latest-thumb img { transform: scale(1.04); }
.landing-latest-play { position: absolute; inset: 0; display: grid; place-items: center; background: linear-gradient(transparent 55%, rgba(0, 0, 0, 0.35)); }
.landing-latest-play svg { filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.45)); transition: transform 0.15s ease; }
.landing-latest-feature:hover .landing-latest-play svg { transform: scale(1.1); }

.landing-latest-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: #e33;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}

.landing-latest-thumb.is-text { display: grid; place-items: center; background: linear-gradient(135deg, #2f7a73, #153f3b); }
.landing-latest-quote { font-size: 2.5rem; font-weight: 700; color: rgba(255, 255, 255, 0.85); letter-spacing: 0.2em; }
.landing-latest-body { display: grid; gap: 8px; padding: 18px 20px 20px; }
.landing-latest-meta { display: flex; align-items: center; gap: 10px; color: rgba(242, 247, 246, 0.65); font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.landing-latest-new { padding: 2px 8px; border-radius: 6px; background: #f5c451; color: #3a2a00; font-size: 0.6875rem; font-weight: 800; letter-spacing: 0.08em; }
.landing-latest-body h3 { margin: 0; color: #fff; font-size: 1.25rem; line-height: 1.45; }

.landing-latest-body p {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: rgba(242, 247, 246, 0.76);
  font-size: 0.9375rem;
  line-height: 1.7;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.landing-latest-cta { justify-self: start; margin-top: 4px; color: #8fd0c7; font-weight: 700; }
.landing-latest-list { display: grid; grid-auto-rows: 1fr; gap: 10px; margin: 0; padding: 0; list-style: none; }
.landing-latest-list li { display: grid; }

.landing-latest-list a {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  transition: background var(--transition), border-color var(--transition);
}

.landing-latest-list a:hover { background: rgba(255, 255, 255, 0.1); border-color: rgba(143, 208, 199, 0.5); }
.landing-latest-mini { position: relative; display: grid; place-items: center; aspect-ratio: 16 / 9; border-radius: 10px; background: #000; overflow: hidden; }
.landing-latest-mini img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

.landing-latest-mini span {
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(227, 51, 51, 0.92);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.6875rem;
  padding-left: 2px;
}

.landing-latest-mini.is-text { background: linear-gradient(135deg, #2f7a73, #1f5c57); color: rgba(255, 255, 255, 0.85); font-size: 1.25rem; font-weight: 700; }
.landing-latest-item { display: grid; gap: 4px; min-width: 0; }

.landing-latest-item strong {
  display: -webkit-box;
  color: #fff;
  overflow: hidden;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.5;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.landing-latest-item-meta { color: rgba(242, 247, 246, 0.6); font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.landing-latest-item-video { color: #ff8a80; font-weight: 600; }

@media (max-width: 900px) {
  .landing-latest-grid { grid-template-columns: minmax(0, 1fr); }
  .landing-latest-list { grid-auto-rows: auto; }
}

@media (max-width: 640px) {
  .landing-latest { padding: 22px 16px; border-radius: 18px; gap: 18px; }
  .landing-latest-head { flex-direction: column; align-items: flex-start; gap: 14px; }
  .landing-latest-list a { grid-template-columns: 104px minmax(0, 1fr); gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .landing-latest-dot { animation: none; }
  .landing-latest-feature, .landing-latest-thumb img { transition: none; }
  .landing-latest-feature:hover { transform: none; }
  .landing-latest-feature:hover .landing-latest-thumb img { transform: none; }
}

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

.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-size: 1.0625rem; line-height: 1.5; }
.guide-card p { margin: 0; color: var(--text-secondary); font-size: 0.875rem; line-height: 1.7; }

/* 每日財經：卡片上的日期、列表分頁與單篇結尾的上一篇／下一篇 */
.news-card-date { color: var(--text-secondary); font-size: 0.8125rem; }
.news-pager { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; max-width: 720px; margin: 28px auto; }

.guide-index-head { max-width: 720px; margin-bottom: 32px; }
.guide-index-head h1 { margin: 8px 0 12px; font-size: 2rem; }
.guide-index-yt { display: flex; align-items: center; gap: 8px; margin: 12px 0 0; color: var(--text-secondary); font-size: 0.9375rem; }
.guide-index-yt svg { flex: none; }

.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-size: clamp(1.625rem, 3.6vw, 2.125rem); line-height: 1.4; }
.prose h2 { margin: 40px 0 12px; 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 code { font-family: inherit; }
.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; }
/* 文章裡的圖表（/images/guides）：一律放在淺色底卡片上，深色模式也看得清楚 */
.prose img { display: block; max-width: 100%; height: auto; margin: 8px auto 20px; padding: 12px; border: 1px solid var(--border);
  border-radius: var(--radius); background: #fff; box-sizing: border-box; }
.prose-author { margin: -12px 0 24px !important; padding-bottom: 14px; border-bottom: 1px solid var(--border); color: var(--text-secondary); font-size: 0.8125rem; line-height: 1.7; }
.prose-author a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.news-takeaway { margin: 32px 0 0; padding: 18px 22px; border: 1px solid var(--border); border-left: 4px solid var(--tour-edge);
  border-radius: var(--radius-lg); background: var(--surface-inset); }
.news-takeaway h2 { margin-top: 0; }
.news-takeaway .prose-meta { margin-bottom: 12px !important; }
.news-takeaway > div > :last-child { margin-bottom: 0; }
.prose-meta a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
/* 介紹頁「為什麼需要股債平衡計算器」：純文字段落，寬度和文章一樣好讀 */
.landing-why p { max-width: 760px; margin: 0 0 14px; color: var(--text-secondary); line-height: 1.9; }
.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-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; }

/* 文章對應的影片：先放縮圖，點了才換成 YouTube 播放器 */
.guide-video { margin: 0 0 28px; aspect-ratio: 16 / 9; border-radius: var(--radius-lg); overflow: hidden; background: #000; }
.guide-video iframe { display: block; width: 100%; height: 100%; border: 0; }
.guide-video-play { position: relative; display: block; width: 100%; height: 100%; padding: 0; border: 0; background: #000; cursor: pointer; }
/* 縮圖不套用文章圖片的外框與內距（.prose img） */
.guide-video-play img { display: block; width: 100%; height: 100%; margin: 0; padding: 0; border: 0; border-radius: 0; background: none; object-fit: cover; }
.guide-video-icon { position: absolute; inset: 0; display: grid; place-items: center; }
.guide-video-icon svg { filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.35)); transition: transform 0.15s ease; }
.guide-video-play:hover .guide-video-icon svg,
.guide-video-play:focus-visible .guide-video-icon svg { transform: scale(1.08); }
.guide-video-play:focus-visible { outline: 3px solid var(--brand-400); outline-offset: -3px; }
/* 文章影片下方的「訂閱頻道」：緊貼影片，和內文隔開 */
.guide-video:has(+ .guide-video-sub) { margin-bottom: 12px; }
.guide-video-sub {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 28px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
}
.guide-video-sub svg { flex: none; }
.guide-video-sub p { flex: 1; margin: 0; color: var(--text-secondary); font-size: 0.9375rem; line-height: 1.6; }
.guide-video-sub strong { color: var(--text); }
.guide-video-sub .btn { flex: none; color: var(--text); text-decoration: none; }
@media (max-width: 520px) {
  .guide-video-sub { flex-wrap: wrap; }
  .guide-video-sub p { flex-basis: calc(100% - 40px); }
  .guide-video-sub .btn { width: 100%; }
}

.guide-video-tag {
  justify-self: start;
  display: inline-block;
  margin-bottom: 6px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--brand-100);
  color: var(--brand-600);
  font-size: 0.75rem;
  font-weight: 700;
}

/* 後台文章編輯：目前影片的縮圖 */
.article-video-preview { display: inline-flex; align-items: center; gap: 10px; margin-top: 6px; color: var(--brand-600); font-size: 0.875rem; }
.article-video-preview img { display: block; width: 160px; height: 90px; object-fit: cover; border-radius: 8px; }
.yt-description summary { cursor: pointer; }
.yt-description textarea { margin-top: 8px; font-size: 0.875rem; line-height: 1.6; resize: vertical; }
.yt-description-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 8px; }
.yt-description-actions code { overflow-wrap: anywhere; }
.guide-related h2 { margin: 0 0 16px; font-size: 1.25rem; }
.guide-more { margin: 16px 0 0; text-align: right; font-size: 0.9375rem; }
.site-main > .ad-slot, .guide-main > .ad-slot { max-width: 720px; margin: 32px auto; }

/* 教學文章：寬螢幕右側一欄跟著捲動的廣告（.ad-sidebar），窄螢幕不顯示 */
.ad-sidebar { display: none; }

@media (min-width: 1120px) {
  .guide-layout:has(> .ad-sidebar) { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 40px; }
  .ad-sidebar { display: block; }
  .ad-sidebar .ad-slot { position: sticky; top: 88px; }
  .ad-sidebar .ad-slot-box { min-height: 600px; }
}

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

.ad-slot { display: grid; gap: 4px; }
.ad-slot-label { color: var(--text-muted); font-size: 0.6875rem; letter-spacing: 0.08em; }
/* 廣告載入前先保留高度，載入後不把內容往下推（CLS 影響搜尋排名）；沒有廣告可填時整個版位收起來，不留空白與「廣告」字樣 */
.ad-slot ins.adsbygoogle:not([data-ad-status]) { min-height: 100px; }
.ad-slot:has(ins.adsbygoogle[data-ad-status="unfilled"]) { display: none; }
.guide-list > .ad-slot { grid-column: 1 / -1; }

@media (max-width: 640px) {
  .ad-slot ins.adsbygoogle:not([data-ad-status]) { min-height: 250px; }
}

.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;
}

/* 試用頁計算器下方的說明（伺服器端輸出，給第一次來的人與搜尋引擎） */
.try-intro { width: 100%; max-width: 1280px; margin: 24px 0 0; padding: 24px calc(48px + env(safe-area-inset-right)) 8px 48px;
  border-top: 1px solid var(--border); font-size: 0.9375rem; line-height: 1.8; }
.try-intro > * { max-width: 760px; }
.try-intro h2 { margin: 28px 0 8px; font-size: 1.125rem; }
.try-intro h2:first-child { margin-top: 0; }
.try-intro p { margin: 0 0 12px; color: var(--text-secondary); }
.try-intro ul, .try-intro ol { margin: 0 0 12px; padding-left: 1.4em; color: var(--text-secondary); }
.try-intro li + li { margin-top: 4px; }
.try-intro a { color: var(--brand-600); }

.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-section .alert strong { color: var(--text); overflow-wrap: anywhere; }
.account-section .alert .link-btn { margin-left: 6px; white-space: nowrap; }
.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-remember { font-size: 0.875rem; color: var(--text-secondary); }
.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)); }
  .try-intro { padding: 20px calc(16px + env(safe-area-inset-right)) 8px 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;
  text-decoration: none;
  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-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-result .tool-subhead { margin: 4px 0 -8px; font-size: 1rem; font-weight: 700; }
.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; }
/* 數學公式（KaTeX，/js/math.js）：長的公式在手機上自己左右捲動，不把頁面撐出橫向捲軸 */
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
@media (max-width: 760px) {
  .katex-display > .katex { font-size: 1em; }
}

.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; }
.faq .faq-more { margin-top: -6px; font-size: 0.875rem; }
.faq .faq-more a { color: var(--brand-600); }

/* 作者與更新資訊（工具頁、教學文章結尾）：誰寫的、更新日、資料來源、錯誤回報 */
.trust-box { max-width: 720px; margin: 32px auto 0; padding: 18px 22px; border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text-secondary); font-size: 0.9375rem; line-height: 1.8; }
.trust-box .trust-box-title { margin: 0 0 8px; color: var(--text); font-size: 1.0625rem; }
.trust-box h3 { margin: 12px 0 4px; color: var(--text); font-size: 0.9375rem; }
.trust-box p { margin: 0 0 8px; }
.trust-box p:last-child { margin-bottom: 0; }
.trust-box ul { margin: 0 0 8px; padding-left: 1.3em; }
.trust-box a { color: var(--brand-600); }
.prose .trust-box { margin: 32px 0 0; }
/* 工具總覽下方的「該用哪一個工具」與常見問題 */
.tools-guide { margin-top: 40px; }

/* ---------- 股債平衡計算器（/tools/rebalance）：持股 → 投入與成本 → 試算報告 ---------- */

.rb-badges { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 0; padding: 0; list-style: none; }
.rb-badges li { padding: 4px 12px 4px 10px; border-radius: var(--radius-full); background: var(--brand-100); color: var(--brand-600); font-size: 0.8125rem; font-weight: 600; }
.rb-badges li::before { content: "✓"; margin-right: 6px; }

.rb-tool { display: grid; gap: 20px; }
.rb-panel, .rb-report { padding: 24px 28px 28px; }
.rb-panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.rb-panel-head > .btn { flex-shrink: 0; }
.rb-step-title { display: flex; align-items: flex-start; gap: 12px; min-width: 0; }
.rb-step-title h2 { margin: 2px 0 4px; font-size: 1.1875rem; font-weight: 700; }
.rb-step-title p { margin: 0; color: var(--text-secondary); font-size: 0.875rem; line-height: 1.6; }
.rb-step-gap { margin: 28px 0 14px; padding-top: 22px; border-top: 1px solid var(--border); }

.rb-step {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-fill);
  color: var(--on-accent);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.9375rem;
}

/* 標的列：桌機一列一檔，最後一欄是即時算出的市值與目前佔比 */
.rq-rows { display: grid; gap: 8px; }
.rq-head, .rq-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 0.9fr) minmax(0, 0.8fr) minmax(0, 0.9fr) minmax(0, 1fr) minmax(0, 1.1fr) 32px;
  gap: 8px;
  align-items: center;
}
.rq-head { padding: 0 2px; color: var(--text-muted); font-size: 0.75rem; font-weight: 600; }
.rq-row .input { min-height: 40px; padding: 6px 10px; font-size: 15px; }
.rq-cell { display: block; min-width: 0; }
.rq-cell-label { display: none; }
.rq-value { display: grid; gap: 1px; min-width: 0; text-align: right; font-variant-numeric: tabular-nums; }
.rq-value strong { font-size: 0.9375rem; }
.rq-value span { color: var(--text-muted); font-size: 0.75rem; }
.rq-remove { justify-self: end; }
.rb-rows-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.rb-target-sum { font-size: 0.8125rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.rb-target-sum.is-ok { color: var(--sell); }
.rb-target-sum.is-off { color: var(--warning); }
.rb-settings { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px 16px; }
.rb-settings .label { font-weight: 600; }

/* 報告：股債比例「目前 → 執行後」，下面是與主畫面相同的委託單 */
.rb-report .tool-result { gap: 0; }
.rb-split { display: grid; gap: 8px; margin-bottom: 18px; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-inset); }
.rb-split:empty { display: none; }
.rb-split-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 12px; font-size: 0.8125rem; font-weight: 600; }
.rb-split-legend { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; color: var(--text-muted); font-weight: 500; }
.rb-split-legend i { display: inline-block; width: 10px; height: 10px; margin-left: 6px; border-radius: 2px; }
.rb-split-legend i.is-stock { background: var(--cat-stock-fill); }
.rb-split-legend i.is-bond { background: var(--cat-bond-fill); }
.rb-split-legend i.is-target { width: 2px; height: 12px; border-radius: 1px; background: var(--text); }
.rb-split .bq-bar-row { grid-template-columns: 3.5em minmax(0, 1fr) 7.5em; }

.rb-next {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 22px;
  padding: 18px 20px;
  border: 2px solid var(--tour-edge);
  border-radius: var(--radius-lg);
  background: var(--surface-inset);
}
.rb-next-title { font-size: 1.0625rem; font-weight: 700; }
.rb-next p { margin: 4px 0 0; color: var(--text-secondary); font-size: 0.875rem; line-height: 1.6; }
.rb-next .btn { flex-shrink: 0; }

@media (max-width: 900px) {
  .rb-settings { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* 手機：每一檔是一張小卡（代號＋類別＋移除 / 目標、市價、股數 / 市值與佔比） */
@media (max-width: 640px) {
  .rb-panel, .rb-report { padding: 18px 16px 20px; }
  .rb-panel-head { flex-direction: column; gap: 12px; }
  .rq-head { display: none; }
  .rq-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-inset);
  }
  .rq-ticker { grid-column: 1 / 3; grid-row: 1; }
  .rq-category { grid-column: 3; grid-row: 1; }
  .rq-cell-label { display: block; margin-bottom: 3px; color: var(--text-muted); font-size: 0.6875rem; font-weight: 600; }
  .rq-value { grid-column: 1 / 3; text-align: left; display: flex; align-items: baseline; gap: 8px; }
  .rq-remove { grid-column: 3; }
  .rb-next { flex-direction: column; align-items: stretch; }
}

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

.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-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-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-yearly { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 8px; margin-top: -8px; font-size: 0.875rem; color: var(--text-muted); }
.plan-yearly strong { color: var(--brand-600); font-size: 1rem; }
.plan-yearly-tag { padding: 1px 8px; border-radius: var(--radius-full); background: var(--brand-100); color: var(--brand-600); font-size: 0.75rem; font-weight: 700; }
.plan-points { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; font-size: 0.875rem; line-height: 1.6; color: var(--text-secondary); }
.plan-points li { position: relative; padding-left: 22px; }
.plan-points li::before { content: "✓"; position: absolute; left: 0; color: var(--brand-600); font-weight: 700; }
.plan-points strong { color: var(--text); }
.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-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-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; }
.admin-alert-detail { white-space: pre-line; }

/* 後台概況的伺服器狀態：左 Java、右 MySQL，每一項一條用量橫條，超過門檻的項目變成警示色 */
.server-status-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.server-status .tag-ok { background: var(--brand-100); color: var(--accent-fill); }
.server-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.server-panel { display: grid; align-content: start; gap: 10px; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); }
.server-panel h3 { margin: 0; font-size: 0.9375rem; }
.server-list { display: grid; gap: 12px; margin: 0; }
.server-list > div { display: grid; grid-template-columns: 8.5em minmax(0, 1fr); gap: 4px 12px; }
.server-list dt { color: var(--text-secondary); font-size: 0.8125rem; padding-top: 2px; }
.server-list dd { display: grid; gap: 4px; margin: 0; min-width: 0; }
.server-list strong { font-size: 0.9375rem; font-variant-numeric: tabular-nums; }
.server-list .cell-sub { overflow-wrap: anywhere; }
.server-meter { display: block; height: 6px; border-radius: var(--radius-full); background: var(--surface-2); overflow: hidden; }
.server-meter > span { display: block; height: 100%; max-width: 100%; border-radius: inherit; background: var(--accent-fill); }
.server-list > div.is-warn dt, .server-list > div.is-warn strong { color: var(--warning); }
.server-list > div.is-warn .server-meter > span { background: var(--warning); }
.server-foot { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 900px) {
  .server-grid { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .server-list > div { grid-template-columns: 1fr; }
}
.plan-buy { margin: 0 0 10px; }

/* 方案頁的功能對照表 */
.pricing-alert { max-width: 880px; margin: 0 auto 20px; }
.pricing-compare { max-width: 880px; margin: 0 auto 28px; }
.pricing-compare th:not(:first-child), .pricing-compare td:not(:first-child) { width: 7.5em; text-align: center; }
.pricing-compare td:first-child span { display: block; margin-top: 2px; color: var(--text-muted); font-size: 0.8125rem; line-height: 1.5; }
.pricing-compare .yes { color: var(--sell); font-weight: 700; }
.pricing-compare .no { color: var(--text-muted); }
.pricing-premium-row { background: var(--brand-100); }
.pricing-compare a { color: var(--brand-600); }

@media (max-width: 640px) {
  /* 手機：方案兩欄只放勾勾與短字，讓功能說明有空間 */
  .pricing-compare th, .pricing-compare td { padding-left: 10px; padding-right: 10px; }
  .pricing-compare th:not(:first-child), .pricing-compare td:not(:first-child) { width: 4.2em; }
}
.plan-desc { margin: 0; color: var(--text-secondary); line-height: 1.7; }
.plan-trial { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--brand-100); color: var(--brand-600); font-size: 0.875rem; font-weight: 600; }
.plan-trial-note { margin: -6px 0 0; }
.register-trial { margin: 0 0 24px; padding: 10px 12px; border-radius: 10px; background: var(--brand-100); color: var(--brand-600); font-size: 0.8125rem; line-height: 1.6; }
.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-pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 16px; }
.admin-pager .btn { text-decoration: none; }
.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; }
/* min-width / width：預覽裡的長表格不會把整個編輯頁撐出橫向捲軸 */
.editor-preview { max-width: none; min-width: 0; width: 100%; box-sizing: border-box; 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); }
.admin-row-actions { justify-content: flex-end; }
/* 表格裡的操作：按鈕與小表單排成一列，多出一顆按鈕（例如扣款中的「停止扣款」）也不會把整列撐高；放不下時表格橫向捲動 */
.table .admin-inline { flex-wrap: nowrap; align-items: flex-start; white-space: nowrap; }
/* 需要多填欄位的操作（開通天數、停止扣款確認、手動發票號碼）：先只顯示按鈕，按了才在格子裡展開 */
.admin-pop { display: inline-block; vertical-align: top; }
.admin-pop > summary { list-style: none; }
.admin-pop > summary::-webkit-details-marker { display: none; }
/* 展開的面板跟按鈕一樣寬（輸入框用百分比寬度，不會把欄位撐寬） */
.admin-pop-panel { display: grid; gap: 8px; margin-top: 8px; padding: 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); white-space: normal; }
.admin-pop-panel .input-xs, .admin-inline .admin-pop-panel .input-xs { width: 100%; min-width: 0; }
.admin-pop-panel .btn { white-space: nowrap; }
.table td form { margin: 0; }
.admin-confirm { display: inline-flex; align-items: center; gap: 4px; font-size: 0.75rem; color: var(--text-secondary); }
/* 說明文字與下面的表格、卡片之間留一點距離 */
.admin-content > p.text-muted { margin: 0 0 12px; }

/* 後台「成效」 */
.analytics-head { flex-wrap: wrap; margin-bottom: 4px; }
.analytics-periods { flex-wrap: nowrap; }
.analytics-head .seg-group + .seg-group { margin-left: .5rem; }
.analytics-views .seg-btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.analytics-weekly-card { grid-template-columns: minmax(0, 1fr); } /* 寬表格留在 .table-wrap 裡橫向捲動，不要把卡片撐寬 */
.analytics-matrix td.zero { color: var(--text-muted); }
.analytics-matrix th[scope=row] { white-space: nowrap; font-weight: 600; }
.week-current { margin-left: 4px; }
.analytics-periods .seg-btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.funnel-table td { vertical-align: middle; }
.funnel-bar-col { width: 34%; }
.funnel-bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.funnel-bar > span { display: block; height: 100%; min-width: 2px; border-radius: 999px; background: var(--accent-fill); }
.analytics-chart { position: relative; height: 280px; }
.analytics-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }
.analytics-grid .admin-card { align-content: start; }
.admin-content .analytics-grid .table { min-width: 0; }
.analytics-link { color: var(--text); text-decoration: none; font-weight: 600; }
.analytics-link:hover { color: var(--brand-600); text-decoration: underline; }
.analytics-range { margin: 0 0 16px; }
.analytics-notes { margin: 0; padding-left: 20px; display: grid; gap: 6px; color: var(--text-secondary); font-size: 0.875rem; }
@media (max-width: 760px) {
  .analytics-head .seg-group + .seg-group { margin-left: 0; }
}
@media (max-width: 900px) {
  .analytics-grid { grid-template-columns: minmax(0, 1fr); }
  .funnel-bar-col { width: 24%; }
}
.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) {
  .tool-fields { grid-template-columns: minmax(0, 1fr); }
  .compare-grid { grid-template-columns: minmax(0, 1fr); }
  .tools-search { max-width: none; }
  .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; }
/* 說明欄（綠界的訊息、扣款狀況）可以換行，表格才不會被長句撐出橫向捲軸 */
.admin-content .table td.cell-sub { white-space: normal; min-width: 8em; }

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

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-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; }

/* 核心功能的入口：比其他連結醒目一點 */
.site-nav > a.site-nav-core { color: var(--brand-600); font-weight: 600; }

/* 帳號設定的入口（登入後才有） */
.site-nav > a.site-nav-account { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- 帳號設定頁（/account） ---------- */

.account-page { max-width: 640px; margin: 0 auto; }
.account-page-head { margin-bottom: 20px; }
.account-notice { margin-bottom: 16px; }
.account-page-head h1 { margin: 4px 0 0; font-size: 1.75rem; }
.account-card { padding: 24px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); }
.account-card .account-section h2 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 1rem; }
.account-card [data-slot="msg"]:empty { display: none; }
.account-card a { color: var(--brand-600); }
.account-card .alert { margin: 0; }

@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; }
  .account-card { padding: 16px; }
}


/* ---------- 手機版的左側選單（menu.js）：公開頁面 760px 以下、計算機主畫面 900px 以下 ---------- */

.menu-btn {
  display: none;
  flex: none;
  width: 40px;
  height: 40px;
  margin-left: -8px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.menu-btn:hover { background: var(--surface-2); }

.drawer { display: none; position: fixed; inset: 0; z-index: 100; visibility: hidden; pointer-events: none; }
.drawer.is-open { visibility: visible; pointer-events: auto; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(15, 18, 16, 0.45); opacity: 0; transition: opacity 0.2s ease; }
.drawer.is-open .drawer-backdrop { opacity: 1; }
.drawer-panel {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(300px, 84vw);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px calc(16px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 8px 0 24px rgba(0, 0, 0, 0.12);
  transform: translateX(-100%);
  transition: transform 0.22s ease;
}
.drawer.is-open .drawer-panel { transform: none; }
.drawer-head .site-brand span { display: inline; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 0 10px 4px; border-bottom: 1px solid var(--border); }
.drawer-nav { display: grid; gap: 2px; }
.drawer-group { margin-top: 4px; padding-top: 10px; border-top: 1px solid var(--border); }
.drawer-nav a,
.drawer-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.drawer-nav a:hover, .drawer-item:hover { background: var(--surface-2); }
.drawer-nav a.drawer-core { color: var(--brand-600); font-weight: 600; }
.drawer-item svg, .drawer-nav a svg { flex: none; color: var(--text-secondary); }
.drawer-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; padding: 4px 4px 4px 12px; color: var(--text); }
.drawer-sub { display: block; color: var(--text-muted); font-size: 0.8125rem; overflow-wrap: anywhere; }
html.drawer-locked { overflow: hidden; }

@media (max-width: 760px) {
  .site-header-inner { justify-content: flex-start; gap: 8px; }
  .site-brand { margin-right: auto; }
  .site-header .menu-btn { display: inline-flex; }
  .site-nav-page { display: none; }
  /* 帳號設定已經在左側選單裡，頂列不再放小人圖示 */
  .site-nav > a.site-nav-account { display: none; }
  .drawer-site { display: block; }
}

/* 計算機主畫面（深色頂列）：漢堡鈕取代圖標，首頁、手冊、帳號、深淺色、登出都在選單裡 */
@media (max-width: 900px) {
  .rail .menu-btn-app { display: inline-flex; margin-left: -4px; color: var(--rail-text); }
  .rail .menu-btn-app:hover { background: rgba(255, 255, 255, 0.08); }
  .app-shell .rail .rail-brand,
  .app-shell .rail .rail-help,
  .app-shell .rail .rail-user { display: none; }
  .drawer-app { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  .drawer-panel, .drawer-backdrop { transition: none; }
}

/* ---------- 工具總覽的核心工具卡 ---------- */

.tool-tile-core {
  grid-column: 1 / -1;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px 28px;
  padding: 26px 28px;
  border: 2px solid var(--brand-400);
  background: var(--brand-100);
}

.tool-tile-core h2 { font-size: 1.375rem; }
.tool-core-body { display: grid; gap: 8px; }
.tool-core-points { display: grid; gap: 4px; margin: 4px 0 0; padding-left: 1.2em; color: var(--text-secondary); font-size: 0.875rem; line-height: 1.6; }
.tool-core-btn { white-space: nowrap; }

@media (max-width: 640px) {
  .tool-tile-core { grid-template-columns: minmax(0, 1fr); padding: 20px; }
  .tool-core-btn { justify-self: stretch; }
}

/* ==========================================================================
   Premium 進階功能：左側選單、總覽卡片、合併檢視彈窗
   ========================================================================== */

.rail-premium-list { display: flex; flex-direction: column; gap: 4px; }
.rail-premium-btn { color: var(--rail-muted); }
.rail-premium-btn:hover { color: var(--rail-text); }
.rail-lock { margin-left: auto; display: inline-flex; color: var(--rail-muted); opacity: 0.8; }
.rail-trial { padding: 4px 14px 0; color: #f0c877; font-size: 0.75rem; }

.premium-card .card-head { justify-content: space-between; }
.premium-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.premium-tile {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-inset);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition);
}
.premium-tile:hover { border-color: var(--brand-400); }
.premium-tile-icon { display: inline-flex; flex-shrink: 0; padding: 8px; border-radius: 10px; background: var(--brand-100); color: var(--brand-600); }
.premium-tile-text { display: grid; gap: 4px; min-width: 0; }
.premium-tile-text strong { display: inline-flex; align-items: center; gap: 6px; font-size: 0.9375rem; }
.premium-tile-text strong svg { color: var(--text-muted); }
.premium-tile-text span { color: var(--text-secondary); font-size: 0.8125rem; line-height: 1.55; }
.premium-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; color: var(--text-secondary); font-size: 0.875rem; }
.premium-card-foot .btn { flex-shrink: 0; text-decoration: none; }

.modal-h3 { margin: 22px 0 10px; font-size: 1rem; font-weight: 700; }
.combined-kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin: 12px 0; }
.combined-split { margin: 4px 0 8px; }
.combined-orders { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.combined-order { padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-inset); }
.combined-order-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.combined-order-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; font-size: 0.875rem; }
.combined-order-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.combined-order-amt { margin-left: auto; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.combined-months { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.combined-month { display: grid; gap: 2px; padding: 8px 10px; border-radius: 10px; background: var(--surface-inset); font-size: 0.8125rem; }
.combined-month span { color: var(--text-muted); }
.combined-month strong { font-variant-numeric: tabular-nums; }

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

@media (max-width: 640px) {
  .premium-card-foot { flex-direction: column; align-items: stretch; }
  .combined-months { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* 彈窗內文的連結（帳號設定、合併檢視）與網站其他地方一致 */
.modal-body a:not(.btn) { color: var(--brand-600); }

/* ==========================================================================
   通知：右上角的鈴鐺與通知清單
   桌機在內容區右上角（跟頁首對齊，頁首與上方的提示讓出位置）；900px 以下放在頂列。
   ========================================================================== */

.page.has-bell { position: relative; }
.page.has-bell .page-head { padding-right: 56px; }
.page.has-bell > .alert { margin-right: 56px; }

.notice-bell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-secondary);
  font-family: inherit;
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition);
}

.notice-bell:hover { background: var(--brand-100); color: var(--brand-600); }

.notice-bell-main {
  position: absolute;
  top: 40px;
  right: calc(48px + env(safe-area-inset-right));
  z-index: 2;
}

.notice-bell-rail { display: none; }

/* 未讀數：深淺色都用同一個紅底白字，深色模式的 --danger 太淺、白字看不清楚 */
.notice-badge {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 2px solid var(--surface);
  border-radius: 10px;
  background: #c0392b;
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.notice-badge[hidden] { display: none; }

@media (max-width: 1280px) {
  .notice-bell-main { right: calc(32px + env(safe-area-inset-right)); }
}

@media (max-width: 900px) {
  .notice-bell-main { display: none; }
  .page.has-bell .page-head { padding-right: 0; }
  .page.has-bell > .alert { margin-right: 0; }

  .notice-bell-rail {
    display: inline-flex;
    width: 44px;
    height: 44px;
    border-color: var(--rail-line);
    background: var(--rail-2);
    color: var(--rail-text);
  }

  .notice-bell-rail:hover { background: var(--rail-line); color: var(--rail-text); }
  .notice-bell-rail .notice-badge { border-color: var(--rail); }
}

/* 通知清單：桌機像下拉選單一樣接在鈴鐺下方（位置由 app.js 依鈴鐺計算），手機照一般彈窗從下方滑出 */
@media (min-width: 641px) {
  .overlay-notices {
    align-items: flex-start;
    justify-content: flex-end;
    background: rgba(23, 20, 55, 0.18);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .overlay-notices .modal { max-height: calc(100dvh - var(--notice-top, 88px) - 20px); }
}

.notice-list {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}

.notice-item {
  display: flex;
  gap: 12px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}

.notice-item:first-child { padding-top: 0; border-top: none; }

.notice-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-muted);
}

.notice-item.unread .notice-icon { background: var(--brand-100); color: var(--brand-600); }
.notice-text { flex: 1; min-width: 0; }
.notice-title { font-weight: 600; line-height: 1.5; overflow-wrap: anywhere; }

.notice-item.unread .notice-title::after {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 6px;
  border-radius: 50%;
  background: #c0392b;
  vertical-align: middle;
}

.notice-body {
  margin: 4px 0 0;
  color: var(--text-secondary);
  font-size: 0.875rem;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.notice-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.notice-meta .btn { flex-shrink: 0; }
.notice-note { margin: 0; color: var(--text-muted); font-size: 0.75rem; line-height: 1.6; }

.notice-plan {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  line-height: 1.6;
}

.notice-plan svg { flex-shrink: 0; margin-top: 3px; color: var(--brand-600); }
.notice-plan .link-btn,
.notice-plan a { margin-left: 6px; font-weight: 600; }

.notice-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px 8px;
  color: var(--text-muted);
  font-size: 0.875rem;
  text-align: center;
}

.notice-empty p { margin: 0; }
