/* ──────────────────────────────────────────────────────────────────────────────
 * AllocLab UI v5 — /dashboard page
 * 6 sections：header / brief / portfolio / watchlist / events / upsell
 * 設計來源：K 給的 Dashboard standalone HTML (2026-04-25)
 * 共用元件參考 40-components.css；本檔只放 page-level layout + page-only style
 * ────────────────────────────────────────────────────────────────────────────── */

/* ---------- Header ---------- */
.dash-hdr__row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  height: var(--header-h);
  padding: 0 8px 0 var(--pad-x);
  gap: 4px;
}
.dash-hdr__row--4 {
  grid-template-columns: 1fr auto auto auto;
}
.dash-greet {
  padding: 4px var(--pad-x) 14px;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.dash-greet__hi {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--al-ink);
}
.dash-greet__date {
  font-size: 0.78rem;
  color: var(--al-ink-muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Main shell ---------- */
.dash-main {
  padding: var(--sp-4) var(--pad-x);
  display: flex;
  flex-direction: column;
  gap: var(--gap-card);
}

/* ---------- Section: AI Brief ---------- */
.dash-brief {
  background: linear-gradient(
    180deg,
    rgba(217, 119, 87, 0.06) 0%,
    var(--al-surface) 60%
  );
  border: 1px solid var(--al-border-soft);
  border-radius: var(--radius-card);
  padding: var(--sp-4);
}
.dash-brief__head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: var(--sp-3);
}
.dash-brief__head .title {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--al-ink);
  flex: 0 0 auto;
}
.dash-brief__head .conf {
  margin-left: auto;
  font-size: var(--fs-xs);
  color: var(--al-ink-muted);
}
.dash-brief__head .conf b {
  color: var(--al-ink);
  font-weight: 600;
}
.dash-brief__headline {
  font-family: var(--ff-display);
  font-size: 1.18rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--al-ink);
  margin-bottom: 6px;
}
.dash-brief__summary {
  font-size: var(--fs-base);
  line-height: var(--lh-relaxed);
  color: var(--al-ink-2);
  margin-bottom: var(--sp-3);
}
.dash-brief__chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: var(--sp-3);
}
.dash-brief__detail {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--t-base) var(--ease);
  overflow: hidden;
}
.dash-brief__detail.is-open {
  grid-template-rows: 1fr;
  margin-bottom: var(--sp-3);
}
.dash-brief__detail > .lyr-wrap {
  min-height: 0;
}
.dash-brief__lyr {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-top: 1px solid var(--al-border-soft);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
}
.dash-brief__lyr .k {
  color: var(--al-ink-muted);
  font-weight: 500;
  font-size: var(--fs-sm);
}
.dash-brief__lyr .v {
  color: var(--al-ink-2);
}
.dash-brief__lyr .v strong {
  color: var(--al-ink);
  font-weight: 600;
}
.dash-brief__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--al-border-soft);
  margin-top: var(--sp-2);
}
.dash-brief__cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--al-accent);
  font-weight: 600;
  font-size: var(--fs-base);
  min-height: 44px;
}
.dash-brief__cta svg { width: 16px; height: 16px; }
.dash-brief__toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  color: var(--al-ink-2);
  font-size: var(--fs-sm);
  min-height: 44px;
}
.dash-brief__toggle svg {
  width: 14px;
  height: 14px;
  transition: transform var(--t-fast) var(--ease);
}
.dash-brief__toggle[aria-expanded="true"] svg { transform: rotate(180deg); }

/* ---------- Section: Portfolio ---------- */
.dash-port {
  cursor: pointer;
}

/* W4-D7-A2：fetch 失敗 inline hint */
.dash-port__hint {
  padding: 6px 10px;
  margin-bottom: 8px;
  background: var(--al-surface);
  border: 1px solid var(--al-line);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: var(--al-ink-muted);
}

/* W4-D7-A2：登入空 holdings 空狀態 */
.dash-port__empty {
  text-align: center;
  padding: 24px 16px;
  color: var(--al-ink-muted);
  grid-column: 1 / -1;
}
.dash-port__empty-title {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--al-ink);
  margin-bottom: 6px;
}
.dash-port__empty-desc {
  font-size: 0.8125rem;
  line-height: 1.6;
  margin: 0 0 8px 0;
}
.dash-port__empty-hint {
  display: inline-block;
  font-size: 0.8125rem;
  color: var(--al-accent);
}
.dash-port__grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--sp-4);
  align-items: start;
}
.dash-port__stack {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: var(--sp-3);
}
.dash-port__stack > i {
  display: block;
  height: 100%;
}
.dash-port__legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dash-port__legend .row {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: var(--fs-sm);
}
.dash-port__legend .sw {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}
.dash-port__legend .nm { color: var(--al-ink); }
.dash-port__legend .pct {
  color: var(--al-ink-muted);
  font-variant-numeric: tabular-nums;
}
.dash-port__pnl {
  text-align: right;
  min-width: 110px;
}
.dash-port__pnl .v {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.dash-port__pnl .v.up { color: var(--al-up); }
.dash-port__pnl .v.dn { color: var(--al-dn); }
.dash-port__pnl .sub {
  margin-top: 6px;
  font-size: var(--fs-sm);
  color: var(--al-ink-muted);
  line-height: 1.55;
}
.dash-port__pnl .sub .up { color: var(--al-up); }
.dash-port__pnl .sub .dn { color: var(--al-dn); }
.dash-port__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--al-border-soft);
  margin-top: var(--sp-3);
  color: var(--al-accent);
  font-weight: 500;
  font-size: var(--fs-base);
}

/* ---------- Section: Watchlist ---------- */
.dash-wl__filters {
  display: flex;
  gap: 6px;
}
.dash-wl__filters .al-pill-filter {
  min-height: 32px;
  padding: 4px 10px;
  font-size: var(--fs-sm);
}
.dash-wl__list {
  display: flex;
  flex-direction: column;
}

/* ── W4-D1i：mini stats row（N 檔 · 累計 X.XX% · M 檔有 Alert）──────────── */
.dash-wl__stats {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 0;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--al-line);
  font-size: 0.8125rem;
  color: var(--al-ink-muted);
}
.dash-wl__stat {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.dash-wl__stat .num {
  font-variant-numeric: tabular-nums;
  color: var(--al-ink);
}
.dash-wl__stat .num.up { color: var(--al-up); }
.dash-wl__stat .num.dn { color: var(--al-dn); }
.dash-wl__sep { opacity: 0.4; }

/* ── W4-D1i：fetch 失敗 inline hint（保留 mock 不破畫面）──────────── */
.dash-wl__hint {
  padding: 6px 10px;
  margin-bottom: 8px;
  background: var(--al-surface);
  border: 1px solid var(--al-line);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: var(--al-ink-muted);
}

/* ── W4-D1i：登入空 watchlist 空狀態 ─────────────────────────────── */
.dash-wl__empty {
  text-align: center;
  padding: 24px 16px;
  color: var(--al-ink-muted);
}
.dash-wl__empty-title {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--al-ink);
  margin-bottom: 6px;
}
.dash-wl__empty-desc {
  font-size: 0.8125rem;
  line-height: 1.6;
  margin: 0 0 12px 0;
}
.dash-wl__empty-cta {
  display: inline-block;
  padding: 6px 14px;
  background: var(--al-accent);
  color: var(--al-bg);
  border-radius: var(--radius-pill);
  font-size: 0.8125rem;
  text-decoration: none;
  transition: opacity 120ms ease;
}
.dash-wl__empty-cta:hover { opacity: 0.9; }
.dash-wl__row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 4px var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--al-border-soft);
  text-decoration: none;
  color: inherit;
}
.dash-wl__row:last-child { border-bottom: 0; padding-bottom: 0; }
.dash-wl__row:first-child { padding-top: 0; }
.dash-wl__row .ident {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.dash-wl__row .ident .code {
  font-family: var(--ff-mono);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--al-ink-muted);
  font-variant-numeric: tabular-nums;
}
.dash-wl__row .ident .name {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--al-ink);
}
.dash-wl__row .px {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.dash-wl__row .px .p {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--al-ink);
}
.dash-wl__row .px .c {
  font-size: var(--fs-sm);
  margin-top: 2px;
}
.dash-wl__row .px .c.up { color: var(--al-up); }
.dash-wl__row .px .c.dn { color: var(--al-dn); }
.dash-wl__row .meta {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: var(--fs-sm);
}
.dash-wl__row .meta .ai {
  color: var(--al-ink-2);
  flex: 1 1 auto;
  min-width: 0;
}
.dash-wl__row .meta .qmeta {
  color: var(--al-ink-muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

/* ---------- Section: Events ---------- */
.dash-evt__list {
  display: flex;
  flex-direction: column;
}

/* W4-D8：fetch 失敗 inline hint */
.dash-evt__hint {
  padding: 6px 10px;
  margin-bottom: 8px;
  background: var(--al-surface);
  border: 1px solid var(--al-line);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: var(--al-ink-muted);
}

/* W4-D8：登入空 events 空狀態 */
.dash-evt__empty {
  text-align: center;
  padding: 24px 16px;
  color: var(--al-ink-muted);
}
.dash-evt__empty-title {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--al-ink);
  margin-bottom: 6px;
}
.dash-evt__empty-desc {
  font-size: 0.8125rem;
  line-height: 1.6;
  margin: 0 0 12px 0;
}
.dash-evt__empty-cta {
  display: inline-block;
  padding: 6px 14px;
  background: var(--al-accent);
  color: var(--al-bg);
  border-radius: var(--radius-pill);
  font-size: 0.8125rem;
  text-decoration: none;
  transition: opacity 120ms ease;
}
.dash-evt__empty-cta:hover { opacity: 0.9; }
.dash-evt__row {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--al-border-soft);
  text-decoration: none;
  color: inherit;
}
.dash-evt__row:last-child { border-bottom: 0; padding-bottom: 0; }
.dash-evt__row:first-child { padding-top: 0; }
.dash-evt__time {
  font-family: var(--ff-mono);
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--al-ink);
  display: flex;
  flex-direction: column;
  font-variant-numeric: tabular-nums;
}
.dash-evt__time .day {
  font-family: var(--ff-sans);
  font-size: var(--fs-xs);
  color: var(--al-ink-muted);
  font-weight: 500;
  margin-top: 2px;
}
.dash-evt__tags {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.dash-evt__tags .sym {
  font-family: var(--ff-mono);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--al-accent);
}
.dash-evt__tags .type {
  padding: 2px 8px;
  border-radius: var(--radius-chip);
  background: var(--al-active-bg);
  color: var(--al-accent);
  font-size: var(--fs-xs);
  font-weight: 500;
}
.dash-evt__tags .type.alt {
  background: var(--al-surface-2);
  color: var(--al-ink-2);
}
.dash-evt__desc {
  color: var(--al-ink-2);
  font-size: var(--fs-sm);
  line-height: var(--lh-relaxed);
}

/* ---------- Section: Upsell ---------- */
.dash-upsell {
  position: relative;
  background: linear-gradient(
    140deg,
    rgba(217, 119, 87, 0.10) 0%,
    var(--al-surface) 70%
  );
  border: 1px solid rgba(217, 119, 87, 0.24);
  border-radius: var(--radius-card);
  padding: var(--sp-4);
}
.dash-upsell.is-dismissed { display: none; }
/* D-FIX-2：Plus/Pro 用戶進場 SSR user_tier=free default 會閃過 Upsell card 400ms。
   預設 visibility:hidden、hydrateUser 完成後才 reveal（is-loaded class）。
   訪客 / Free 用戶 hydrateUser 早 return 也會直接加 is-loaded（不延遲顯示）。 */
.dash-upsell[data-needs-tier-check]:not(.is-loaded):not(.is-dismissed) {
  visibility: hidden;
}
.dash-upsell__x {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--al-ink-muted);
}
.dash-upsell__x:hover { color: var(--al-ink); background: var(--al-surface); }
.dash-upsell__x svg { width: 16px; height: 16px; }
.dash-upsell__title {
  margin: var(--sp-2) 0;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--al-ink);
}
.dash-upsell__title em {
  font-style: normal;
  color: var(--al-accent);
}
.dash-upsell__meta {
  font-size: var(--fs-sm);
  color: var(--al-ink-muted);
  margin-bottom: var(--sp-3);
}
.dash-upsell__meta .price {
  color: var(--al-ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.dash-upsell__cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  background: var(--al-accent);
  color: #fff;
  font-weight: 600;
  font-size: var(--fs-base);
  min-height: 44px;
}
.dash-upsell__cta:hover { background: var(--al-accent-2); }
.dash-upsell__cta svg { width: 16px; height: 16px; }

/* ---------- AI 觀察重新生成 icon ---------- */
.dash-ai-regen {
  margin-left: auto;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--al-ink-muted);
  border-radius: 50%;
  transition: background var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease);
}
.dash-ai-regen:hover { background: var(--al-surface-2); color: var(--al-accent); }
.dash-ai-regen svg { width: 14px; height: 14px; }

/* ---------- m8++ 接線：dashboard 「最近通知」widget ---------- */
.dash-notif {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.dash-notif__list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.dash-notif__item {
  display: block;
  padding: var(--sp-3);
  background: var(--al-bg);
  border: 1px solid var(--al-border-soft);
  border-radius: var(--radius-inner);
  text-decoration: none;
  color: inherit;
  transition: border-color var(--t-fast) var(--ease),
              background var(--t-fast) var(--ease);
}
.dash-notif__item:hover,
.dash-notif__item:focus-visible {
  border-color: var(--al-accent);
  background: var(--al-active-bg);
}
.dash-notif__item.is-unread {
  border-left: 3px solid var(--al-accent);
  padding-left: calc(var(--sp-3) - 3px + 1px);
}
.dash-notif__item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  margin-bottom: 4px;
}
.dash-notif__kind {
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--al-ink-muted);
  background: var(--al-surface-2);
  padding: 2px 6px;
  border-radius: var(--radius-pill);
}
.dash-notif__time {
  font-size: var(--fs-xs);
  color: var(--al-ink-muted);
}
.dash-notif__title {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--al-ink);
  line-height: 1.4;
}
.dash-notif__foot {
  display: flex;
  justify-content: flex-end;
}
.dash-notif__more {
  font-size: var(--fs-xs);
  color: var(--al-accent);
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-inner);
  transition: background var(--t-fast) var(--ease);
}
.dash-notif__more:hover { background: var(--al-active-bg); }

/* ---------- Skeleton loaders ---------- */
@keyframes al-skel-shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}
.al-skel {
  display: block;
  border-radius: 3px;
  background: linear-gradient(90deg,
    var(--al-surface-2) 0%,
    var(--al-border) 50%,
    var(--al-surface-2) 100%
  );
  background-size: 400px 100%;
  animation: al-skel-shimmer 1.4s infinite linear;
}
.dash-wl__row--skel,
.dash-evt__row--skel {
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--al-border-soft);
}
.dash-wl__row--skel:last-child,
.dash-evt__row--skel:last-child { border-bottom: 0; }
.dash-port__skel { display: flex; flex-direction: column; gap: 8px; padding: 4px 0; }
.dash-no-login {
  padding: 20px 0;
  text-align: center;
  font-size: var(--fs-sm);
  color: var(--al-ink-muted);
}
