/* =====================================================================
   Portfolio — Modern, clean redesign (warm paper palette)
   Source of truth: fsa/project/Portfolio Redesign.html (Claude Design handoff)
   ===================================================================== */

:root {
  --bg-page: #faf7f2;
  --bg-card: #ffffff;
  --bg-soft: #f3ede3;
  --bg-soft-2: #ede5d8;
  --line: #e9e1d3;
  --line-soft: #f1ebde;
  --line-strong: #ddd2bf;

  --ink: #1f1a17;
  --ink-2: #4a3f37;
  --ink-3: #7a6a59;
  --ink-4: #a89a85;

  --accent: #b8612e;
  --accent-soft: #fbecdb;
  --accent-line: #e9c8a8;

  --pos: #2f7a4e;
  --pos-soft: #e6f1ea;
  --neg: #b04030;
  --neg-soft: #f8e3df;
  --warn: #a07024;

  --r-lg: 16px;
  --r-md: 10px;
  --r-sm: 6px;

  --shadow-1: 0 1px 0 rgba(31, 26, 23, 0.04), 0 6px 18px -10px rgba(31, 26, 23, 0.10);
  --shadow-2: 0 1px 0 rgba(31, 26, 23, 0.04), 0 14px 36px -16px rgba(31, 26, 23, 0.18);

  /* Font stacks fall through to system fonts so first paint is not blocked on
     Google Fonts (especially Noto Sans SC, which ships ~18 woff2 subsets,
     ~1 MB total on cold cache). Web fonts swap in once Inter / Fraunces /
     Noto load. Chinese system fallbacks cover the CN text path. */
  --font-display: 'Fraunces', 'Noto Sans SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', ui-serif, Georgia, serif;
  --font-body: 'Inter', 'Noto Sans SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Mono', 'Menlo', 'Consolas', monospace;
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-page);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'cv11', 'ss01';
}

body.portfolio-body {
  background-image:
    radial-gradient(1200px 600px at 10% -10%, rgba(184, 97, 46, 0.04), transparent 60%),
    radial-gradient(900px 500px at 110% 0%, rgba(47, 122, 78, 0.03), transparent 60%);
  background-attachment: fixed;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; padding: 0; }

input, select, textarea { font: inherit; color: inherit; }

.hidden { display: none !important; }

.num,
.workspace-kpi-value,
.summary-value,
.metric-stack strong,
.account-pill,
.performance-mini-card strong,
.performance-axis strong {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
}

/* ---------- Shell ---------- */
.portfolio-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 28px 16px;
}

/* ---------- Top nav ---------- */
.portfolio-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 0 18px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 36px;
}

.portfolio-brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}
.portfolio-brand .brand-mark {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: linear-gradient(135deg, var(--accent), #d6864e 65%, #e9b282);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.55);
}
.portfolio-brand .brand-tag {
  color: var(--ink-3);
  font-size: 13px;
  font-weight: 400;
  font-family: var(--font-body);
}

.portfolio-nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.portfolio-nav-right .nav-link {
  color: var(--ink-3);
  padding: 7px 12px;
  border-radius: var(--r-sm);
  transition: background-color 0.15s, color 0.15s;
}
.portfolio-nav-right .nav-link:hover,
.portfolio-nav-right .nav-link.is-active {
  color: var(--ink);
  background: var(--bg-soft);
}
.nav-divider {
  width: 1px;
  height: 18px;
  background: var(--line);
  margin: 0 6px;
}

/* ---------- Buttons (scoped) ---------- */
.portfolio-body .btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--ink-2);
  transition: all 0.15s ease;
  white-space: nowrap;
  text-transform: none;
  letter-spacing: 0;
  font-family: var(--font-body);
  cursor: pointer;
}
.portfolio-body .btn:hover {
  border-color: var(--line-strong);
  color: var(--ink);
  background: var(--bg-card);
  transform: none;
}
.portfolio-body .btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fdfaf4;
}
.portfolio-body .btn-primary:hover {
  background: #2c241f;
  border-color: #2c241f;
  color: #fff;
}
.portfolio-body .btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.portfolio-body .btn-accent:hover {
  background: #a55626;
  border-color: #a55626;
}
.portfolio-body .btn-sm {
  padding: 6px 10px;
  font-size: 12px;
}

.ghost-button {
  background: transparent;
  border: 0;
  color: var(--ink-3);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  transition: background-color 0.15s, color 0.15s;
}
.ghost-button:hover { background: var(--bg-soft); color: var(--ink); }

/* ---------- Page head — quiet "Portfolio" + thesis anchor ---------- */
.page-head {
  margin-bottom: 18px;
}
.page-head h1 {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  line-height: 1;
  margin: 0 0 4px;
  color: var(--ink-3);
  text-transform: none;
}
.page-thesis {
  margin: 0;
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.4;
}
.page-thesis-eyebrow {
  font-family: var(--font-mono, ui-monospace, 'JetBrains Mono', monospace);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}
.page-thesis-sep {
  color: var(--ink-4);
}
.page-thesis-line {
  color: var(--ink-2);
  font-style: italic;
}

/* ---------- Hero metric (replaces the 4-KPI grid) ---------- */
.portfolio-hero {
  margin-bottom: 28px;
  padding: 28px 0 24px;
  border-bottom: 1px solid var(--line);
}
.portfolio-hero.hidden { display: none; }
.hero-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}
.hero-numbers {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}
.hero-eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.hero-figure {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
  font-variant-numeric: tabular-nums;
  margin: 4px 0 6px;
}
.hero-figure-primary {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 42px;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--ink);
}
.hero-figure-divider {
  font-size: 14px;
  color: var(--ink-4);
  font-weight: 400;
}
.hero-figure-secondary {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 18px;
  color: var(--ink-3);
}
.hero-figure-pct {
  margin-left: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.hero-action-line {
  font-size: 14px;
  color: var(--ink-2);
  margin: 0;
  line-height: 1.45;
}
.hero-market-line {
  font-size: 12px;
  color: var(--ink-4);
  margin: 2px 0 0;
  line-height: 1.5;
}
.hero-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 24px;
}
.hero-status {
  margin: 14px 0 0;
  font-size: 12px;
  color: var(--ink-4);
}
.hero-status:empty { display: none; }

/* ---------- Toolbar ---------- */
.portfolio-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  margin-bottom: 24px;
  box-shadow: var(--shadow-1);
  flex-wrap: wrap;
}
.toolbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--ink-3);
  font-size: 12px;
}
.toolbar-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.toolbar-divider {
  width: 1px;
  height: 18px;
  background: var(--line);
}
.toolbar-status { margin: 0; color: var(--ink-3); }
.toolbar-status:empty { display: none; }

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--pos);
  display: inline-block;
  box-shadow: 0 0 0 3px rgba(47, 122, 78, 0.18);
  animation: live-pulse 2.2s infinite;
}
@keyframes live-pulse { 50% { box-shadow: 0 0 0 6px rgba(47, 122, 78, 0); } }

.toolbar-right {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.sheet-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-line);
  font-size: 12px;
  font-weight: 500;
}
.sheet-source-link {
  font-size: 12px;
  color: var(--ink-3);
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 3px;
}
.sheet-source-link:hover { color: var(--ink); }

/* ---------- Demo ribbon (single line, not a billboard) ---------- */
.portfolio-demo-ribbon {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  margin-bottom: 18px;
  font-size: 12px;
  color: var(--ink-3);
}
.portfolio-demo-ribbon.hidden { display: none; }
.demo-tag {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--accent);
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
}
.demo-ribbon-copy a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  margin-left: 4px;
}
.demo-ribbon-copy a:hover { text-decoration: underline; }

/* ---------- KPI strip (structured + fallback) ---------- */
.kpi-strip {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr;
  gap: 0;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 4px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-1);
}
.kpi-strip:empty { display: none; }

.kpi-strip--fallback { grid-template-columns: 1fr 1fr; }

.workspace-overview-grid > .workspace-kpi,
.kpi-strip > .workspace-kpi,
.kpi-strip > .summary-card {
  background: transparent;
  border: 0;
  padding: 22px 24px;
  border-right: 1px solid var(--line-soft);
  border-radius: 0;
  box-shadow: none;
  position: relative;
  display: block;
  margin: 0;
}
.kpi-strip > :last-child { border-right: 0; }

.workspace-kpi-label,
.summary-label {
  font-size: 11px;
  color: var(--ink-4);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 500;
  margin-bottom: 10px;
}
.workspace-kpi-value,
.summary-value {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 30px;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin-bottom: 8px;
  color: var(--ink);
}
.workspace-overview-grid > .workspace-kpi:first-child .workspace-kpi-value,
.kpi-strip--fallback > .summary-card:first-child .summary-value {
  font-size: 38px;
}
.workspace-kpi-meta,
.summary-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-3);
  margin: 0;
}

/* When the structured KPI strip has content, hide the fallback summary */
.portfolio-main:has(#workspace-overview-grid > .workspace-kpi) .kpi-strip--fallback {
  display: none;
}
/* When empty state is shown, hide the fallback summary too */
.portfolio-main:has(#portfolio-empty:not(.hidden)) .kpi-strip--fallback {
  display: none;
}

/* ---------- Workspace section ---------- */
.workspace-section { margin-bottom: 28px; }

.workspace-section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.workspace-section-head h3,
.section-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 20px;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--ink);
}
.section-sub {
  color: var(--ink-3);
  font-size: 13px;
  margin: 4px 0 0;
}
.section-sub-quiet {
  color: var(--ink-4);
  font-size: 11px;
  margin: 0 0 10px;
}
.section-sub-quiet:empty { display: none; }
.section-quiet-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0 0 8px;
}

/* ---------- Performance card ---------- */
.perf-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 24px 26px 22px;
  box-shadow: var(--shadow-1);
}

.performance-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.perf-title-block { display: flex; flex-direction: column; gap: 4px; }
.perf-title-block h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  margin: 0;
  color: var(--ink);
}
.perf-title-block .section-sub { margin-top: 0; }

.performance-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.select-pill,
.performance-controls select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 30px 7px 14px;
  font: inherit;
  font-size: 12px;
  color: var(--ink-2);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
    linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 14px) 14px, calc(100% - 10px) 14px;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.performance-range-switch {
  display: inline-flex;
  background: var(--bg-soft);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.range-pill {
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-3);
  border-radius: 999px;
  letter-spacing: 0.02em;
  border: 0;
  background: transparent;
  cursor: pointer;
  transition: color 0.15s, background-color 0.15s;
}
.range-pill.is-active {
  background: var(--bg-card);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(31, 26, 23, 0.06), 0 0 0 1px var(--line);
}
.range-pill:hover:not(.is-active) { color: var(--ink); }

.performance-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  margin-bottom: 22px;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  overflow: hidden;
}
.performance-summary-grid:empty { display: none; }
.performance-mini-card {
  padding: 14px 18px;
  border-right: 1px solid var(--line-soft);
  background: transparent;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.performance-mini-card:last-child { border-right: 0; }
.performance-mini-card span {
  font-size: 11px;
  color: var(--ink-4);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
}
.performance-mini-card strong {
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
}
.performance-mini-card.is-positive strong { color: var(--pos); }
.performance-mini-card.is-negative strong { color: var(--neg); }

.performance-chart {
  position: relative;
  width: 100%;
  min-height: 260px;
}
.performance-svg {
  width: 100%;
  height: 260px;
  display: block;
  overflow: visible;
}
.performance-grid-line { stroke: var(--line-soft); stroke-dasharray: 2 4; }
.performance-area { fill: url(#performance-fill); }
.performance-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.performance-baseline-line {
  stroke: var(--ink-4);
  stroke-width: 1;
  stroke-dasharray: 3 4;
  opacity: 0.6;
}
.performance-last-dot {
  fill: var(--accent);
  stroke: #fff;
  stroke-width: 2;
}
.performance-axis {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 11px;
  color: var(--ink-4);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}
.performance-axis strong {
  color: var(--ink);
  font-weight: 600;
  font-size: 13px;
  font-family: var(--font-mono);
}
.performance-empty {
  padding: 60px 16px;
  text-align: center;
  color: var(--ink-3);
  font-size: 13px;
  background: var(--bg-soft);
  border-radius: var(--r-md);
}

/* ---------- Holdings table card ---------- */
.table-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.workspace-table-wrap,
.portfolio-table-wrap {
  overflow-x: auto;
}

.workspace-table,
.portfolio-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.workspace-table thead th,
.portfolio-table thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-4);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbf8f1;
  white-space: nowrap;
}
.workspace-table thead th.right,
.workspace-table thead th.num-col,
.portfolio-table thead th.right {
  text-align: right;
}
.workspace-table tbody td,
.portfolio-table tbody td {
  padding: 16px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}
.workspace-table tbody tr:last-child td,
.portfolio-table tbody tr:last-child td { border-bottom: 0; }
.workspace-table tbody tr:hover td,
.portfolio-table tbody tr:hover td { background: #fbf7ee; }
.workspace-table tbody tr.is-expanded-row td { background: #fbf7ee; }
.workspace-table tbody tr:hover .inline-action-button {
  border-color: var(--line-strong);
}

/* Company name cell — ticker badge */
.company-ticker-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.company-ticker-badge .ticker-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--bg-soft-2);
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
  color: var(--ink-2);
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

/* metric-stack: JS-rendered cell content for holdings */
.metric-stack {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.metric-stack strong {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.metric-stack span {
  font-size: 11px;
  color: var(--ink-4);
}
.metric-stack.is-positive strong,
.metric-stack.is-positive span { color: var(--pos); }
.metric-stack.is-negative strong,
.metric-stack.is-negative span { color: var(--neg); }

/* num-col cells are right-aligned (the new table uses .num-col on header
   and body cells where right-align is wanted) */
.company-allocation-table thead th.num-col,
.company-allocation-table tbody td.num-col { text-align: right; }
.company-allocation-table tbody td:last-child { text-align: right; }

/* ---- Holdings table: 5-column layout (cost+target / progress / gap / market) ---- */

/* Column 1: ticker + account chips beneath. No more avatar square. */
.alloc-company {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.alloc-ticker {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.alloc-account-chips {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  color: var(--ink-4);
  font-size: 11px;
}
.alloc-account-chips .account-chip {
  background: var(--bg-soft);
  border: 0;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 500;
  color: var(--ink-3);
  letter-spacing: 0.02em;
}

/* Column 2: stacked cost / target. Bold numbers on top, percentages below. */
.alloc-cost-target {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-variant-numeric: tabular-nums;
}
.alloc-cost-line {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font-size: 14px;
  color: var(--ink);
}
.alloc-cost-line strong { font-weight: 600; letter-spacing: -0.01em; }
.alloc-cost-line .alloc-target-money { color: var(--ink-3); font-weight: 500; }
.alloc-sep { color: var(--ink-4); font-size: 11px; }
.alloc-cost-sub {
  font-size: 11px;
  color: var(--ink-4);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.alloc-cost-sub .alloc-target-pct { display: inline-flex; align-items: center; }

/* Column 3: progress bar — the visual anchor for the row. */
.alloc-progress-col { width: 200px; padding-left: 14px; padding-right: 14px; }
.alloc-progress-wrap {
  width: 100%;
  display: flex;
  align-items: center;
}
.alloc-progress-track {
  position: relative;
  height: 8px;
  width: 100%;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow: hidden;
  /* Subtle tick at 100% — the target line */
  background-image: linear-gradient(to right,
    transparent calc(100% - 2px),
    var(--line-strong) calc(100% - 2px),
    var(--line-strong) 100%);
}
.alloc-progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width 200ms ease;
}
.alloc-progress-fill.is-over { background: var(--warn); }
.alloc-progress-over {
  position: absolute;
  left: 100%;
  top: 0;
  bottom: 0;
  background: var(--neg);
  border-radius: 0 999px 999px 0;
  transition: width 200ms ease;
}
.alloc-progress-empty { color: var(--ink-4); font-size: 12px; }

/* Column 4: gap to target — signed money + status word. The action signal. */
.alloc-gap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-variant-numeric: tabular-nums;
}
.alloc-gap strong {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.alloc-gap span {
  font-size: 11px;
  color: var(--ink-4);
}
.alloc-gap.is-positive strong { color: var(--pos); }
.alloc-gap.is-positive span { color: var(--pos); }
.alloc-gap.is-negative strong { color: var(--neg); }
.alloc-gap.is-negative span { color: var(--neg); }

/* Column 5: market cluster — quiet, secondary curiosity column. */
.alloc-market {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-variant-numeric: tabular-nums;
}
.alloc-market strong {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
}
.alloc-market span {
  font-size: 11px;
  color: var(--ink-4);
  letter-spacing: 0;
}
.alloc-market.is-quiet strong { color: var(--ink-4); }

/* Footer: target % sum + remaining. Sanity check for the planning surface. */
.alloc-footer-row td {
  padding: 12px 16px !important;
  background: var(--bg-soft) !important;
  border-bottom: 0 !important;
  border-top: 1px solid var(--line);
}
.alloc-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.alloc-footer strong {
  color: var(--ink);
  font-weight: 600;
  font-size: 13px;
}
.alloc-footer-sep { color: var(--ink-4); }
.alloc-footer.is-over strong { color: var(--neg); }
.alloc-footer.is-over { color: var(--neg); }

.company-row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* The whole holdings row is now a single click target that toggles the
   drilldown. Replaces the old 编辑 + 详情 button cluster. */
.company-allocation-table tbody tr.allocation-row {
  cursor: pointer;
  transition: background-color 120ms ease;
}
.company-allocation-table tbody tr.allocation-row:hover {
  background: var(--bg-soft);
}
.company-allocation-table tbody tr.allocation-row.is-expanded-row {
  background: var(--bg-soft);
}
.allocation-row-toggle {
  width: 36px;
  text-align: center;
  color: var(--ink-3);
}
th.allocation-row-toggle { width: 36px; }
.allocation-chevron {
  display: inline-block;
  font-size: 11px;
  line-height: 1;
  transition: transform 120ms ease;
}
.allocation-row.is-expanded-row .allocation-chevron { color: var(--ink); }

/* Drilldown head now carries the "清空 TICKER" action. Layout: title left,
   account-count + clear stacked on right. */
.drilldown-head-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.drilldown-head-actions .btn-link.is-danger {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: var(--r-sm);
  color: var(--neg);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.drilldown-head-actions .btn-link.is-danger:hover {
  background: var(--neg-soft);
  border-color: var(--neg);
}

.inline-action-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: all 0.15s ease;
  cursor: pointer;
}
.inline-action-button:hover {
  border-color: var(--line-strong);
  color: var(--ink);
  background: var(--bg-soft);
}

/* Editable target % button — dashed pill matching design */
.target-display-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px dashed var(--line);
  background: transparent;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--ink-2);
  font-size: 13px;
  cursor: text;
  transition: all 0.15s ease;
  min-width: 64px;
  justify-content: flex-end;
}
.target-display-button::after {
  content: '✎';
  font-size: 10px;
  opacity: 0.5;
  margin-left: 2px;
}
.target-display-button:hover {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
}

.target-cancel-button {
  font-size: 11px;
  color: var(--ink-3);
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
}
.target-cancel-button:hover { color: var(--ink); background: var(--bg-soft); }

.target-editor {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.target-input-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  box-shadow: none;
  transition: border-color 120ms ease, background-color 120ms ease, box-shadow 120ms ease;
  cursor: text;
}
.target-input-wrap:hover {
  border-color: var(--line);
  background: var(--bg-soft);
}
.target-input-wrap:focus-within {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.target-input-wrap.is-empty .row-target-input::placeholder { color: var(--ink-3); }
.target-input-wrap span { font-size: 11px; color: var(--ink-3); }
.row-target-input,
.target-input-wrap .row-target-input {
  border: 0;
  outline: none;
  background: transparent;
  width: 56px;
  text-align: right;
  font-family: var(--font-body);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 13px;
  color: var(--ink);
  padding: 0;
  cursor: text;
  /* Strip the native spinner so the value reads like plain text by default. */
  appearance: textfield;
  -moz-appearance: textfield;
}
.row-target-input::-webkit-outer-spin-button,
.row-target-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.target-input-wrap:focus-within .row-target-input {
  appearance: auto;
  -moz-appearance: auto;
}
.target-input-wrap:focus-within .row-target-input::-webkit-outer-spin-button,
.target-input-wrap:focus-within .row-target-input::-webkit-inner-spin-button {
  -webkit-appearance: auto;
}
.row-target-input:focus { outline: none; }

/* Account chip list inside the holdings table */
.account-chip-list {
  display: inline-flex;
  gap: 4px;
  flex-wrap: wrap;
  max-width: 180px;
}
.account-chip {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--ink-2);
  border: 1px solid var(--line-soft);
  white-space: nowrap;
}

.table-action-label {
  font-size: 11px;
  color: var(--ink-4);
  letter-spacing: 0.04em;
}

/* Drilldown row — clean grid-aligned list, no boxy cards. */
.allocation-detail-row td {
  padding: 0 16px 16px;
  background: #fbf7ee;
  border-bottom: 1px solid var(--line-soft);
}
.drilldown-panel {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px 18px 6px;
  display: grid;
  gap: 4px;
}
.drilldown-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--ink-3);
  padding-bottom: 10px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--line-soft);
  gap: 12px;
  flex-wrap: wrap;
}
.drilldown-head-summary {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  min-width: 0;
}
.drilldown-head-summary strong { color: var(--ink); font-size: 14px; }
.drilldown-summary-text {
  font-size: 12px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.drilldown-head-actions {
  display: inline-flex;
  align-items: center;
  gap: 14px;
}
.drilldown-account-count {
  font-size: 11px;
  color: var(--ink-4);
}

/* The row grid: account / shares / cost / actions — all columns align. */
.drilldown-rows {
  display: grid;
  grid-template-columns: minmax(120px, 1.2fr) minmax(70px, 1fr) minmax(90px, 1fr) auto;
  gap: 0 16px;
  font-variant-numeric: tabular-nums;
}
.drilldown-row {
  display: contents;
}
.drilldown-row > span {
  padding: 10px 0;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
  color: var(--ink);
}
.drilldown-row:last-child > span {
  border-bottom: 0;
}
.drilldown-row.drilldown-row-head > span {
  padding: 6px 0 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-4);
  border-bottom: 1px solid var(--line);
}
.drilldown-row .num,
.drilldown-cell-num {
  justify-content: flex-end;
  text-align: right;
  font-weight: 500;
  color: var(--ink);
}
.drilldown-row.drilldown-row-head .num {
  font-weight: 600;
  color: var(--ink-4);
}
.drilldown-cell-account {
  font-weight: 600;
  color: var(--ink);
}
.drilldown-cell-actions {
  justify-content: flex-end;
  gap: 6px;
}
.drilldown-cell-actions .inline-action-button {
  padding: 4px 12px;
  font-size: 11px;
}
.drilldown-empty {
  padding: 18px 0;
  font-size: 12px;
  color: var(--ink-3);
  display: flex;
  align-items: center;
  gap: 10px;
}
.drilldown-edit-form {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}
.drilldown-edit-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}
.drilldown-edit-fields .portfolio-field {
  margin: 0;
}
.drilldown-edit-fields label {
  font-size: 11px;
  color: var(--ink-3);
}
.drilldown-edit-fields input {
  padding: 8px 10px;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  width: 100%;
}
.drilldown-edit-fields .input-with-suffix input {
  padding-left: 26px;
}
.drilldown-edit-actions {
  display: flex;
  gap: 6px;
}
.drilldown-row-edit {
  grid-column: 1 / -1;
}
.drilldown-account-card.is-editing {
  border-color: var(--accent-line);
  background: #fdfaf4;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.drilldown-empty {
  padding: 16px;
  text-align: center;
  color: var(--ink-3);
  font-size: 13px;
}

/* ---------- Account cards ---------- */
.account-card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.account-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 22px;
  box-shadow: var(--shadow-1);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.account-card.is-expanded {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-2);
}
.account-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.account-card-head h4 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
  color: var(--ink);
}
.account-card-head p {
  font-size: 11px;
  color: var(--ink-3);
  margin: 0;
  letter-spacing: 0.04em;
}
.account-pill {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-3);
  background: var(--bg-soft);
  padding: 4px 9px;
  border-radius: 999px;
  font-weight: 500;
  white-space: nowrap;
}

.account-card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.account-card-metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  overflow: hidden;
}
.account-mini-metric {
  padding: 12px 14px;
  border-right: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.account-mini-metric:last-child { border-right: 0; }
.account-mini-metric span {
  font-size: 11px;
  color: var(--ink-4);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.account-mini-metric strong {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.account-position-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.account-position-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  gap: 12px;
}
.account-position-row:last-child { border-bottom: 0; }
.account-position-row.is-editable { padding: 11px 0; }

.account-position-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.account-position-copy strong { font-weight: 600; color: var(--ink); }
.account-position-copy span { color: var(--ink-3); font-size: 12px; }

.account-position-actions {
  display: inline-flex;
  gap: 6px;
  flex-shrink: 0;
}

.account-position-more {
  margin-top: 8px;
  padding: 8px 12px;
  width: 100%;
  text-align: center;
  border-radius: var(--r-sm);
  background: var(--bg-soft);
  border: 1px dashed var(--line);
  color: var(--ink-3);
  font-size: 12px;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.account-position-more:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }

/* ---------- Modal overlay ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: modal-fade-in 0.2s ease;
}
.modal-overlay.hidden { display: none !important; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(31, 26, 23, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  animation: modal-slide-up 0.25s ease;
}
.modal-close-button {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--ink-3);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}
.modal-close-button:hover { background: var(--bg-soft-2); color: var(--ink); }
@keyframes modal-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-slide-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Asset distribution ---------- */
.asset-distribution-section { margin-bottom: 24px; }
.asset-dist-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.asset-dist-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-1);
}
.asset-dist-bar {
  display: flex;
  height: 36px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-soft);
  gap: 2px;
}
.asset-dist-segment {
  height: 100%;
  min-width: 4px;
  transition: opacity 0.15s;
  position: relative;
  cursor: default;
}
.asset-dist-segment:first-child { border-radius: 999px 0 0 999px; }
.asset-dist-segment:last-child { border-radius: 0 999px 999px 0; }
.asset-dist-segment:only-child { border-radius: 999px; }
.asset-dist-segment:hover { opacity: 0.8; }
.asset-dist-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 14px;
}
.asset-dist-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-2);
  cursor: default;
}
.asset-dist-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}
.asset-dist-legend-item strong {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.asset-dist-legend-item span {
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

/* ---------- Forms (composers + sheet import) ---------- */
.portfolio-form-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 22px 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-1);
}
.form-card-head h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  margin: 0 0 4px;
  color: var(--ink);
}
.form-card-head .form-note { margin: 0 0 14px; }

.transaction-composer {
  background: var(--bg-card);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-2);
}
.transaction-composer-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
  gap: 16px;
}
.transaction-composer-head h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  margin: 0 0 4px;
  color: var(--ink);
}

.transaction-mode-switch {
  display: inline-flex;
  background: var(--bg-soft);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  margin-bottom: 14px;
}
/* The browser-default [hidden] { display: none } loses to explicit display:
   flex / grid on .portfolio-field / .editor-grid-2, so force it back. The
   mode-aware renderer toggles `hidden` on each data-mode-only node. */
.portfolio-field[hidden],
.editor-grid-2[hidden] { display: none !important; }
.mode-pill {
  padding: 6px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-3);
  border-radius: 999px;
  border: 0;
  background: transparent;
  cursor: pointer;
  transition: color 0.15s, background-color 0.15s, box-shadow 0.15s;
}
.mode-pill.is-active {
  background: var(--bg-card);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(31, 26, 23, 0.08), 0 0 0 1px var(--line);
}

.portfolio-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.portfolio-grid-fields {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.portfolio-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.portfolio-field label {
  font-size: 11px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}
.portfolio-field input,
.portfolio-field select {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--bg-card);
  font-size: 13px;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: var(--font-body);
  line-height: 1.4;
}
/* Drop the native chevron on the account select so it visually matches the
   text input next to it (the typeahead). Keep a custom chevron drawn with
   the existing CSS variables — same trick we use on .performance-controls. */
.portfolio-field select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 30px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
    linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 16px) 18px, calc(100% - 12px) 18px;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
  cursor: pointer;
}
.portfolio-field input:focus,
.portfolio-field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.portfolio-field-muted { background: var(--bg-soft); border-radius: var(--r-sm); padding: 10px 12px; }
.portfolio-field-muted label { color: var(--ink-4); }
.field-help { margin: 0; font-size: 11px; color: var(--ink-3); line-height: 1.5; }
.field-help.is-error { color: var(--neg); }

/* Ticker typeahead — validated symbol picker (transaction & company forms). */
.portfolio-typeahead {
  position: relative;
}
.portfolio-typeahead input {
  width: 100%;
}
.portfolio-typeahead.is-valid input {
  border-color: var(--pos);
  box-shadow: 0 0 0 3px var(--pos-soft);
}
.portfolio-typeahead.is-invalid input {
  border-color: var(--neg);
  box-shadow: 0 0 0 3px var(--neg-soft);
}
.portfolio-typeahead-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-2);
  max-height: 280px;
  overflow-y: auto;
  z-index: 60;
}
.portfolio-typeahead-dropdown.is-open { display: block; }
.portfolio-typeahead-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--line-soft);
  font-family: var(--font-body);
  font-size: 13px;
}
.portfolio-typeahead-item:last-child { border-bottom: none; }
.portfolio-typeahead-item:hover,
.portfolio-typeahead-item.is-active {
  background: var(--bg-soft);
}
.portfolio-typeahead-item .pt-ticker {
  font-weight: 600;
  color: var(--ink);
  min-width: 80px;
  font-variant-numeric: tabular-nums;
}
.portfolio-typeahead-item .pt-name {
  color: var(--ink-3);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.portfolio-typeahead-item .pt-exchange {
  font-size: 10px;
  color: var(--ink-4);
  background: var(--bg-soft);
  padding: 2px 6px;
  border-radius: 999px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.portfolio-typeahead-item mark {
  background: var(--accent-soft);
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}
.portfolio-typeahead-empty,
.portfolio-typeahead-loading {
  padding: 10px 14px;
  font-size: 12px;
  color: var(--ink-3);
}

.form-note,
.table-note {
  font-size: 12px;
  color: var(--ink-3);
  margin: 0;
}
.form-error,
.form-success {
  font-size: 12px;
  margin: 0;
  padding: 8px 12px;
  border-radius: var(--r-sm);
}
.form-error { background: var(--neg-soft); color: var(--neg); }
.form-success { background: var(--pos-soft); color: var(--pos); }

.sheet-import-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.sheet-state-note {
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--accent);
  padding: 8px 12px;
  border-radius: var(--r-sm);
  font-size: 12px;
  margin: 0;
}

/* ---------- Empty state ---------- */
.portfolio-empty {
  background: var(--bg-card);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-lg);
  padding: 48px 24px;
  text-align: center;
  margin-bottom: 24px;
}
.portfolio-empty h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  color: var(--ink);
  margin: 0 0 6px;
}
.portfolio-empty p { margin: 0; color: var(--ink-3); font-size: 13px; }

/* ---------- Sheet grid (legacy) ---------- */
.sheet-grid-shell { margin-bottom: 24px; }
.sheet-grid-table td.is-number { text-align: right; font-variant-numeric: tabular-nums; }
.sheet-grid-table td.is-positive { color: var(--pos); }
.sheet-grid-table td.is-negative { color: var(--neg); }
.sheet-grid-table td.is-empty { color: var(--ink-4); }
.sheet-grid-table tr.is-summary-row td {
  background: var(--bg-soft);
  font-weight: 600;
  color: var(--ink);
}

/* ---------- Demo legacy holdings table ---------- */
.demo-table-wrap { margin-bottom: 24px; }

/* ---------- Footer ---------- */
.portfolio-footer {
  max-width: 1280px;
  margin: 32px auto 0;
  padding: 22px 28px 36px;
  border-top: 1px solid var(--line-soft);
  font-size: 12px;
  color: var(--ink-4);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .kpi-strip { grid-template-columns: 1fr 1fr; }
  .kpi-strip > .workspace-kpi,
  .kpi-strip > .summary-card { border-right: 0; border-bottom: 1px solid var(--line-soft); }
  .account-card-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .portfolio-shell { padding: 0 16px 16px; }
  .portfolio-footer { padding: 22px 16px 36px; }
  .kpi-strip,
  .kpi-strip--fallback { grid-template-columns: 1fr; }
  .kpi-strip > .workspace-kpi,
  .kpi-strip > .summary-card { padding: 18px; }
  .performance-summary-grid { grid-template-columns: repeat(2, 1fr); }
  .performance-summary-grid .performance-mini-card:nth-child(2) { border-right: 0; }
  .performance-summary-grid .performance-mini-card:nth-child(3),
  .performance-summary-grid .performance-mini-card:nth-child(4) { border-top: 1px solid var(--line-soft); }
  .account-card-grid { grid-template-columns: 1fr; }
  .workspace-table,
  .portfolio-table { font-size: 12px; }
  .workspace-table thead th,
  .workspace-table tbody td,
  .portfolio-table thead th,
  .portfolio-table tbody td { padding: 12px 10px; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .portfolio-grid-fields { grid-template-columns: 1fr; }
}

/* =====================================================================
   Onboarding card — first-run welcome state for new users
   ===================================================================== */
.portfolio-onboarding {
  margin: 32px auto 24px;
  max-width: 720px;
  display: flex;
  justify-content: center;
}
.onboarding-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 36px 40px 32px;
  box-shadow: var(--shadow-2);
  text-align: left;
  width: 100%;
  position: relative;
  overflow: hidden;
}
.onboarding-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent) 0%, #d6864e 60%, transparent 100%);
}
.onboarding-eyebrow {
  display: inline-block;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 10px;
}
.onboarding-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
  color: var(--ink);
}
.onboarding-sub {
  margin: 0 0 24px;
  color: var(--ink-3);
  font-size: 14px;
  line-height: 1.6;
}
.onboarding-steps {
  list-style: none;
  margin: 0 0 24px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.onboarding-steps li {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 14px 16px;
  background: var(--bg-soft);
  border-radius: var(--r-md);
  border: 1px solid var(--line-soft);
}
.onboarding-step-num {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}
.onboarding-steps li strong {
  display: block;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}
.onboarding-steps li p {
  margin: 0;
  color: var(--ink-3);
  font-size: 13px;
  line-height: 1.5;
}
.onboarding-cta {
  font-size: 14px;
  padding: 12px 22px;
}
.onboarding-fineprint {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--ink-4);
}
.onboarding-demo-link {
  margin: 14px 0 0;
  font-size: 12px;
  color: var(--ink-4);
}
.onboarding-demo-link a {
  color: var(--ink-3);
  border-bottom: 1px dashed var(--line-strong);
  padding-bottom: 1px;
}
.onboarding-demo-link a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* =====================================================================
   Portfolio Editor drawer — unified Companies / Accounts / Transactions
   ===================================================================== */
.portfolio-editor {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  justify-content: flex-end;
}
.portfolio-editor.hidden { display: none !important; }
.editor-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(31, 26, 23, 0.42);
  backdrop-filter: blur(2px);
}
.editor-panel {
  position: relative;
  width: min(680px, 100%);
  height: 100%;
  background: var(--bg-card);
  border-left: 1px solid var(--line);
  box-shadow: -24px 0 60px -20px rgba(31, 26, 23, 0.30);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: editor-slide-in 220ms ease-out;
}
@keyframes editor-slide-in {
  from { transform: translateX(8px); opacity: 0.7; }
  to { transform: translateX(0); opacity: 1; }
}
.editor-head {
  padding: 20px 24px 14px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
}
.editor-head h3 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  color: var(--ink);
}
.editor-sub {
  margin: 0;
  color: var(--ink-3);
  font-size: 12px;
  line-height: 1.5;
}
.editor-tabs {
  display: flex;
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg-soft);
  padding: 0 8px;
  flex: 0 0 auto;
}
.editor-tab {
  flex: 1;
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-3);
  border-bottom: 2px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}
.editor-tab:hover { color: var(--ink); background: rgba(255, 255, 255, 0.5); }
.editor-tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--bg-card);
}
.editor-tab .tab-count {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.editor-tab.is-active .tab-count {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
}
.editor-tab .tab-count-quiet {
  background: transparent;
  border-color: transparent;
  font-weight: 500;
  color: var(--ink-4);
}
.editor-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 22px 24px 32px;
}
.editor-tab-panel { display: none; }
.editor-tab-panel.is-active { display: block; }

.editor-form {
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 18px 18px 16px;
  margin-bottom: 24px;
}
.editor-form-title {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}
.editor-form-helper {
  margin: 0 0 14px;
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.5;
}
.editor-grid-2 {
  display: grid;
  /* minmax(0, 1fr) prevents intrinsic min-content from forcing a column wider
     than its fair share — without this, a long <option> in a <select> can
     stretch its column and make the other one look narrow. */
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}
.editor-grid-2 > .portfolio-field { min-width: 0; }
.editor-grid-2:last-child { margin-bottom: 0; }
.editor-form .portfolio-field { margin: 0; }
.editor-form-submit {
  margin-top: 14px;
  width: 100%;
  padding: 11px 14px;
}

.input-with-suffix {
  position: relative;
  display: flex;
  align-items: center;
}
.input-with-suffix input {
  width: 100%;
  padding-right: 32px;
}
.input-with-suffix input[type="number"] { padding-left: 12px; }
.input-with-suffix .input-suffix,
.input-with-suffix .input-prefix {
  position: absolute;
  color: var(--ink-4);
  font-size: 13px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.input-with-suffix .input-suffix { right: 12px; }
.input-with-suffix .input-prefix { left: 12px; }
.input-with-suffix:has(.input-prefix) input { padding-left: 26px; padding-right: 12px; }

.muted { color: var(--ink-4); font-weight: 400; font-size: 12px; }

.checkbox-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  user-select: none;
}
.checkbox-line input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.company-form-already-own {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
}
.company-form-purchase-fields {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-sm);
}
.company-form-purchase-fields.hidden { display: none !important; }
.company-form-purchase-fields .editor-grid-2:last-child { margin-bottom: 0; }

.company-form-tip {
  color: var(--warn);
  margin-top: 6px;
  font-size: 11px;
}
.company-form-tip.is-warn {
  color: var(--neg);
  font-weight: 500;
}

.editor-list-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 8px 4px 10px;
}
.editor-list-head h4 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.01em;
  text-transform: uppercase;
}
.editor-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.editor-list-empty {
  padding: 24px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--r-md);
  font-size: 13px;
}
.editor-list-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  transition: border-color 120ms ease, background 120ms ease;
}
.editor-list-row:hover { border-color: var(--line); background: var(--bg-soft); }
.editor-list-row strong {
  display: block;
  font-size: 13px;
  color: var(--ink);
  font-weight: 600;
  letter-spacing: 0.01em;
}
.editor-list-row p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--ink-3);
}
.editor-list-row .row-tag {
  display: inline-block;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 999px;
  margin-left: 6px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.editor-list-row .row-tag.is-watchlist {
  background: var(--bg-soft-2);
  color: var(--ink-3);
}
.editor-list-row .row-tag.is-held {
  background: var(--pos-soft);
  color: var(--pos);
}
.editor-list-row .row-actions {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 220px;
}
.editor-list-row .row-actions .btn-link {
  font-size: 12px;
  color: var(--ink-3);
  padding: 4px 8px;
  border-radius: var(--r-sm);
  transition: background 120ms ease, color 120ms ease;
}
.editor-list-row .row-actions .btn-link:hover { background: var(--bg-soft); color: var(--ink); }
.editor-list-row .row-actions .btn-link.is-danger { color: var(--neg); }
.editor-list-row .row-actions .btn-link.is-danger:hover { background: var(--neg-soft); color: var(--neg); }

/* Editor footer — sits below the tab body for nuclear "清空 Portfolio". */
.editor-footer {
  flex: 0 0 auto;
  padding: 14px 24px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  justify-content: flex-end;
}
.editor-footer .btn-link {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  border: 0;
  background: transparent;
  cursor: pointer;
}
.editor-footer .btn-link.is-danger {
  color: var(--neg);
}
.editor-footer .btn-link.is-danger:hover {
  background: var(--neg-soft);
}
.editor-list-row.is-editing {
  border-color: var(--accent-line);
  background: #fdfaf4;
}
.inline-edit-row {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 10px;
}
.inline-edit-row .portfolio-field {
  margin: 0;
}
.inline-edit-row label {
  font-size: 11px;
  color: var(--ink-3);
}
.inline-edit-row input {
  padding: 8px 10px;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  width: 100%;
}
.inline-edit-row .input-with-suffix input {
  padding-left: 26px;
}
.inline-edit-row .inline-edit-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

/* =====================================================================
   Holdings table — watchlist row treatment
   ===================================================================== */
.company-allocation-table tr.is-watchlist-row td {
  background: linear-gradient(0deg, rgba(184, 97, 46, 0.02), rgba(184, 97, 46, 0.02)),
              var(--bg-card);
}
.company-allocation-table tr.is-watchlist-row .ticker-icon {
  background: var(--bg-soft-2);
  color: var(--ink-3);
}
.watchlist-pill {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  background: var(--bg-soft-2);
  color: var(--ink-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* =====================================================================
   Advanced disclosure (Performance + Asset distribution)
   ===================================================================== */
.advanced-disclosure {
  margin: 16px 0 24px;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  background: var(--bg-card);
}
.advanced-disclosure summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  user-select: none;
}
.advanced-disclosure summary::-webkit-details-marker { display: none; }
.advanced-disclosure summary:hover { color: var(--ink); }
.advanced-disclosure .disclosure-chevron {
  font-size: 12px;
  color: var(--ink-4);
  transition: transform 160ms ease;
}
.advanced-disclosure[open] .disclosure-chevron { transform: rotate(180deg); }
.advanced-disclosure[open] > summary {
  border-bottom: 1px solid var(--line-soft);
}
.advanced-disclosure > section {
  padding: 18px;
  margin-bottom: 0;
}
.advanced-disclosure > section + section {
  border-top: 1px solid var(--line-soft);
}

/* =====================================================================
   Toast notifications
   ===================================================================== */
.portfolio-toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.portfolio-toast {
  background: var(--ink);
  color: #fff;
  padding: 11px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  max-width: 340px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  pointer-events: auto;
  animation: toast-in 0.2s ease forwards;
}
.portfolio-toast.is-out {
  animation: toast-out 0.3s ease forwards;
}
.portfolio-toast.is-success { background: var(--green, #2f7a4e); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(4px); }
}

/* =====================================================================
   Sortable table headers
   ===================================================================== */
.sortable-col {
  cursor: pointer;
  user-select: none;
}
.sortable-col:hover { background: rgba(0,0,0,0.03); }
.sort-indicator {
  font-size: 10px;
  margin-left: 3px;
  color: var(--ink-4);
  vertical-align: middle;
}
.sortable-col.is-sorted .sort-indicator { color: var(--accent, #b8612e); }

/* =====================================================================
   Company tier sections
   ===================================================================== */
.tier-label-desc {
  font-size: 11px;
  font-weight: 400;
  color: var(--ink-4, #bbb);
  margin-left: 5px;
  letter-spacing: 0;
  text-transform: none;
}
.alloc-footer-standalone {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--ink-3, #999);
  border-top: 1px solid var(--rule, #e8e3da);
  margin-top: 2px;
}
.alloc-footer-standalone strong { color: var(--ink, #2a2218); }
.alloc-footer-standalone.is-over strong { color: var(--danger, #c0392b); }

/* =====================================================================
   Drawer responsive
   ===================================================================== */
@media (max-width: 720px) {
  .editor-panel { width: 100%; border-left: 0; }
  .editor-grid-2 { grid-template-columns: 1fr; }
  .onboarding-card { padding: 24px 20px 22px; }
  .onboarding-title { font-size: 22px; }
}

/* No licensed quote source wired: hide the price / market-value column on the
   allocation tables. Toggled by JS (.prices-off on #portfolio-structured-shell)
   so it auto-recovers when a compliant quote provider is added. Cost-based
   columns stay visible — that's the core "control your cost" view. */
.portfolio-structured-shell.prices-off .col-market { display: none; }
