/* ============================================================
   Dashboard + allocation + states
   ============================================================ */

/* ---- KPI cards ---- */
.kpis { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: var(--gap); }
.kpi {
  padding: var(--pad);
  display: flex; flex-direction: column; gap: 10px;
  position: relative; overflow: hidden;
}
.kpi-top { display: flex; align-items: center; gap: 8px; }
.kpi-label { font-size: 12px; color: var(--fg-muted); font-weight: 500; }
.kpi-icon { color: var(--fg-faint); display: grid; place-items: center; }
.kpi-icon svg { width: 15px; height: 15px; }
.kpi-value {
  font-size: clamp(24px, 3.4vw, 30px); font-weight: 600; letter-spacing: -0.025em; line-height: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kpi.hero .kpi-value { font-size: clamp(30px, 4.6vw, 38px); }
.kpi-foot { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--fg-faint); flex-wrap: wrap; }
.kpi.hero { background:
  radial-gradient(120% 140% at 100% 0%, var(--accent-dim), transparent 55%), var(--bg-1); }
.kpi .pl-amt { font-size: clamp(24px, 3.4vw, 30px); font-weight: 600; letter-spacing: -0.025em; line-height: 1; }
.kpi-spark { display: flex; align-items: flex-end; gap: 2px; height: 20px; margin-left: auto; }
.kpi-spark i { width: 3px; border-radius: 2px; background: var(--line); display: block; }

/* ---- dashboard layout ---- */
.dash-grid { display: grid; grid-template-columns: 1.65fr 1fr; gap: var(--gap); align-items: start; }

/* ---- holdings table ---- */
/* The table adapts to the CARD's width (not the viewport) via a container query:
   secondary columns drop out before it has to scroll. Horizontal scroll stays as a
   last resort on very narrow cards. */
.tbl-wrap { overflow-x: auto; container-type: inline-size; container-name: holdings; }
/* tighter, fluid horizontal padding so all columns fit far more often */
table.holdings { width: 100%; border-collapse: collapse; --cell-x: clamp(8px, 1.4cqi, 16px); }
table.holdings th {
  text-align: right; font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--fg-ghost);
  padding: 14px var(--cell-x) 10px; white-space: nowrap;
}
table.holdings th:first-child { text-align: left; }
table.holdings td {
  padding: 0 var(--cell-x); height: var(--row-h); text-align: right; white-space: nowrap;
  border-top: 1px solid var(--line-soft); font-size: 13.5px; font-variant-numeric: tabular-nums;
}
table.holdings td:first-child { text-align: left; padding-left: var(--pad); }
table.holdings tbody tr { cursor: pointer; transition: background .12s ease; }
table.holdings tbody tr:hover { background: var(--bg-2); }
table.holdings tbody tr:hover .row-go { opacity: 1; transform: translateX(0); }
.asset-cell { display: flex; align-items: center; gap: 11px; min-width: 0; }
.asset-cell > div { min-width: 0; }
.asset-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asset-sym { font-size: 11.5px; color: var(--fg-faint); }
.muted-td { color: var(--fg-faint); }
.price-cell { display: inline-flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.price-24 { font-size: 11px; }
.pl-cell { display: inline-flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.row-go { color: var(--fg-ghost); opacity: 0; transform: translateX(-4px); transition: .15s ease; }
.row-go svg { width: 15px; height: 15px; }
.th-end { padding-right: var(--pad) !important; }

/* shed secondary columns as the card narrows (keeps Asset · Price · Value · P/L) */
@container holdings (max-width: 640px) {
  table.holdings .col-avg { display: none; }
}
@container holdings (max-width: 520px) {
  table.holdings .col-amt { display: none; }
}
@container holdings (max-width: 380px) {
  table.holdings .price-24 { display: none; }   /* drop the 24h line, keep the price */
}

/* ---- allocation card ---- */
.alloc-body { padding: var(--pad); }

/* two allocation views (by value / by invested), both visible at once.
   Side-by-side when the card is wide enough, stacked when narrow (container query). */
.alloc-card { container-type: inline-size; container-name: alloc; }
.alloc-split { display: grid; grid-template-columns: 1fr; }
.alloc-pane { min-width: 0; }
.alloc-pane + .alloc-pane { border-top: 1px solid var(--line-soft); }
@container alloc (min-width: 560px) {
  .alloc-split { grid-template-columns: 1fr 1fr; }
  .alloc-pane + .alloc-pane { border-top: 0; border-left: 1px solid var(--line-soft); }
}
.alloc-pane-h {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  padding: 14px var(--pad) 0;
}
.alloc-pane-h .ap-title { font-size: 12px; font-weight: 600; letter-spacing: .02em;
  text-transform: uppercase; color: var(--fg-faint); }
.alloc-pane-h .ap-total { font-size: 13px; font-weight: 600; color: var(--fg); }
.alloc-pane .alloc-body { padding-top: 12px; }

.alloc-donut-wrap { display: flex; align-items: center; gap: 24px; }
.alloc-donut {
  width: 168px; height: 168px; border-radius: 50%; flex: none; position: relative;
  -webkit-mask: radial-gradient(circle 47px at center, transparent 98%, #000 100%);
          mask: radial-gradient(circle 47px at center, transparent 98%, #000 100%);
}
.alloc-donut-hole {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 2px;
}
.dh-label { font-size: 10.5px; color: var(--fg-faint); }
.dh-value { font-size: 19px; font-weight: 600; letter-spacing: -0.02em; }
.dh-sub { font-size: 11px; color: var(--fg-faint); }

.alloc-legend { list-style: none; display: flex; flex-direction: column; gap: 9px; flex: 1; min-width: 0; }
.alloc-legend.wide { margin-top: 18px; }
.alloc-legend li { display: flex; align-items: center; gap: 9px; font-size: 12.5px; cursor: default; transition: opacity .15s ease; }
.alloc-legend li.dim { opacity: 0.4; }
.alloc-legend .sw { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.alloc-legend .lg-sym { font-weight: 600; }
.alloc-legend .lg-pct { margin-left: auto; color: var(--fg-muted); font-variant-numeric: tabular-nums; }
.alloc-legend.wide .lg-pct { margin-left: auto; }
.alloc-legend .lg-val { color: var(--fg-faint); font-variant-numeric: tabular-nums; min-width: 70px; text-align: right; }

/* stacked bar */
.alloc-stack { display: flex; height: 38px; border-radius: 8px; overflow: hidden; gap: 2px; }
.stack-seg { display: grid; place-items: center; transition: opacity .15s ease; min-width: 3px; }
.seg-lbl { font-size: 10.5px; font-weight: 700; color: oklch(0.18 0.01 70); }

/* treemap */
.alloc-treemap { position: relative; width: 100%; height: 220px; }
.tm-cell { position: absolute; padding: 2px; transition: opacity .15s ease; }
.tm-inner { width: 100%; height: 100%; border-radius: 7px; padding: 9px 10px; overflow: hidden;
  background: inherit; display: flex; flex-direction: column; }
.tm-cell .tm-inner { background: color-mix(in oklab, currentColor 0%, transparent); }
.tm-sym { font-size: 12px; font-weight: 700; color: oklch(0.18 0.01 70); }
.tm-pct { font-size: 11px; font-weight: 600; color: oklch(0.22 0.01 70); }
.tm-val { font-size: 10.5px; color: oklch(0.26 0.01 70); margin-top: auto; }

/* vertical bars */
.alloc-vbars { display: flex; align-items: flex-end; gap: 14px; height: 200px; padding-top: 6px; }
.vbar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; transition: opacity .15s ease; }
.vbar-val { font-size: 11.5px; font-weight: 600; color: var(--fg-muted); }
.vbar-track { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.vbar-fill { width: 100%; border-radius: 6px 6px 3px 3px; min-height: 4px; transition: height .5s cubic-bezier(.4,0,.2,1); }
.vbar-sym { font-size: 11.5px; font-weight: 600; color: var(--fg-muted); }

/* ---- skeleton / loading ---- */
@keyframes shimmer { 100% { background-position: -200% 0; } }
.sk {
  background: linear-gradient(90deg, var(--bg-2) 25%, var(--bg-3) 37%, var(--bg-2) 63%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 6px;
}
.sk-line { height: 12px; }

/* ---- empty / error ---- */
.state-pad { padding: 56px var(--pad); display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; }
.state-ico { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center;
  background: var(--bg-2); border: 1px solid var(--line-soft); color: var(--fg-faint); }
.state-ico svg { width: 26px; height: 26px; }
.state-pad h3 { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.state-pad p { font-size: 13.5px; color: var(--fg-faint); max-width: 360px; line-height: 1.5; }
.state-pad.error .state-ico { color: var(--loss); border-color: oklch(0.69 0.150 27 / 0.3); background: var(--loss-dim); }

/* demo state switch in topbar */
.demo-seg { margin-right: 2px; }
.demo-tag { font-size: 9.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--fg-ghost); margin-right: 4px; }

@media (max-width: 1080px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi.hero { grid-column: 1 / -1; }
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: 1fr; }
  .kpi.hero { grid-column: auto; }
  .alloc-donut-wrap { flex-direction: column; }
}

/* ============================================================
   Analysis cards: invested-vs-value, P/L by coin
   ============================================================ */
.analysis-grid { display: grid; grid-template-columns: 1.25fr 1fr; gap: var(--gap); align-items: start; }
@media (max-width: 1080px) { .analysis-grid { grid-template-columns: 1fr; } }

.basis-seg button, .mode-seg button { min-width: 0; }
@media (max-width: 720px) { .mode-seg { display: none; } }

/* invested vs value */
.ivv-body { padding: 8px var(--pad) var(--pad); }
.ivv-key { display: flex; gap: 18px; padding: 4px 0 12px; font-size: 11.5px; color: var(--fg-faint); }
.ivv-key span { display: inline-flex; align-items: center; gap: 7px; }
.ivv-dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.ivv-dot.invested { background: var(--bg-3); box-shadow: 0 0 0 1px var(--line) inset; }
.ivv-dot.value { background: var(--fg-muted); }
.ivv-row { display: grid; grid-template-columns: 150px 1fr auto; align-items: center; gap: 14px;
  padding: 11px 0; border-top: 1px solid var(--line-soft); }
.ivv-coin { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ivv-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ivv-sym { font-size: 11px; color: var(--fg-faint); }
.ivv-bars { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ivv-track { position: relative; display: flex; align-items: center; gap: 8px; }
.ivv-bar { height: 13px; border-radius: 4px; min-width: 3px; transition: width .4s cubic-bezier(.4,0,.2,1); }
.ivv-bar.invested { background: var(--bg-3); box-shadow: 0 0 0 1px var(--line) inset; }
.ivv-bval { font-size: 11.5px; color: var(--fg-faint); white-space: nowrap; }
.ivv-pl { text-align: right; font-size: 13px; font-weight: 600; display: flex; flex-direction: column; align-items: flex-end; white-space: nowrap; }
@media (max-width: 560px) {
  .ivv-row { grid-template-columns: 1fr auto; }
  .ivv-bars { grid-column: 1 / -1; order: 3; }
}

/* P/L by coin (diverging) */
.plc-body { padding: 12px var(--pad) var(--pad); display: flex; flex-direction: column; gap: 3px; }
.plc-row { display: grid; grid-template-columns: 64px 1fr 84px; align-items: center; gap: 10px; padding: 6px 0; }
.plc-label { display: flex; align-items: center; gap: 8px; }
.plc-sym { font-size: 12px; font-weight: 600; }
.plc-track { position: relative; height: 22px; }
.plc-center { position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--line); }
.plc-bar { position: absolute; top: 4px; height: 14px; min-width: 2px; transition: width .4s cubic-bezier(.4,0,.2,1); }
.plc-bar.up { border-radius: 0 4px 4px 0; }
.plc-bar.down { border-radius: 4px 0 0 4px; }
.plc-val { text-align: right; font-size: 12.5px; font-weight: 600; }
.plc-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; padding-top: 12px;
  border-top: 1px solid var(--line-soft); font-size: 12.5px; color: var(--fg-muted); }
