/* --- privatepnl demo dashboard --- */

:root {
  --pos: oklch(0.58 0.13 155);
  --pos-soft: oklch(0.94 0.05 155);
  --neg: oklch(0.58 0.18 25);
  --neg-soft: oklch(0.95 0.06 25);
  --warn: oklch(0.68 0.14 70);
  --warn-soft: oklch(0.96 0.06 80);

  --row: 64px;
  --side-w: 232px;
  --insights-w: 360px;
}
[data-theme="dark"] {
  --pos: oklch(0.78 0.14 155);
  --pos-soft: oklch(0.28 0.06 155);
  --neg: oklch(0.7 0.17 25);
  --neg-soft: oklch(0.28 0.07 25);
  --warn: oklch(0.78 0.14 70);
  --warn-soft: oklch(0.3 0.06 70);
}

html { background: var(--bg-sunk); color: var(--fg); height: 100%; }
/* body must NOT be height-constrained: it's the sticky containing block for
   .demobar (top:0). A fixed 100% height clips the bar to one viewport, so it
   scrolls out of view past the first screen and leaves a gap above .toolbar.
   Letting body grow with content keeps the demo bar pinned the whole way down. */
body { background: var(--bg-sunk); color: var(--fg); min-height: 100%; }

/* --- top demo bar --- */
.demobar {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 9px 18px;
  background: var(--fg);
  color: var(--bg);
  font-size: 13px;
  white-space: nowrap;
}
.demobar a.demobar-cta { color: var(--fg) !important; }
.demobar-l, .demobar-r {
  display: flex;
  align-items: center;
  gap: 14px;
}
.demobar a { color: inherit; }
.demobar a:hover { color: inherit; opacity: 0.8; }

/* theme toggle sits on the inverted demobar — use the bar's fg (var(--bg)) */
.demobar-theme {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--bg) 28%, transparent);
  background: transparent;
  color: var(--bg);
  cursor: pointer;
  flex: none;
}
.demobar-theme:hover {
  background: color-mix(in srgb, var(--bg) 14%, transparent);
  border-color: color-mix(in srgb, var(--bg) 45%, transparent);
  color: var(--bg);
}
.demobar-theme svg { display: block; }
.demobar-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  opacity: 0.75;
}
.demobar-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 3px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 18%, transparent);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.demobar-tag .pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: oklch(0.78 0.14 145);
  box-shadow: 0 0 0 3px color-mix(in srgb, oklch(0.78 0.14 145) 35%, transparent);
  animation: demoPulse 2s infinite;
}
@keyframes demoPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.demobar-cta {
  background: var(--bg);
  color: var(--fg);
  border: 0;
  padding: 6px 12px;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.demobar-cta:hover { opacity: 0.9; }

@media (max-width: 720px) {
  .demobar { padding: 8px 12px; font-size: 12px; }
  .demobar-back span { display: none; }
}

/* --- app shell --- */
.app {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  min-height: calc(100vh - 40px);
  background: var(--bg);
}

.side {
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.side-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px 14px;
  font-weight: 600;
  font-size: 14px;
}
.side-brand .mk {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  background: var(--fg);
  color: var(--bg);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
}
.side-section {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-subtle);
  padding: 14px 10px 6px;
}
.side-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--fg-muted);
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, color 0.12s;
}
.side-item:hover { background: var(--bg-sunk); color: var(--fg); }
.side-item.active {
  background: var(--bg);
  color: var(--fg);
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}
.side-item .ico {
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  flex: 0 0 16px;
  color: var(--fg-subtle);
}
.side-item.active .ico { color: var(--accent); }
.side-item .count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  font-weight: 600;
}
.side-foot {
  margin-top: auto;
  padding: 14px 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--fg-subtle);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sync-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
}
.sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--pos);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--pos) 30%, transparent);
}

/* --- main --- */
.main { min-width: 0; display: flex; flex-direction: column; }

.toolbar {
  position: sticky;
  top: 40px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 28px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.toolbar > * { flex-shrink: 0; }
.tb-period {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--bg);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  position: relative;
}
.tb-period .caret { color: var(--fg-subtle); font-size: 10px; }
.tb-period:hover { border-color: var(--fg-muted); }

.tb-compare {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
  background: var(--bg);
}
.tb-compare button {
  background: transparent;
  border: 0;
  padding: 7px 13px;
  font-size: 13px;
  color: var(--fg-muted);
  cursor: pointer;
  border-right: 1px solid var(--border);
  white-space: nowrap;
}
.tb-compare button:last-child { border-right: 0; }
.tb-compare button.on {
  background: var(--fg);
  color: var(--bg);
  font-weight: 500;
}
.tb-compare button:not(.on):hover { color: var(--fg); background: var(--bg-soft); }

.tb-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-subtle);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tb-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.tb-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 11px;
  font-size: 13px;
  color: var(--fg-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.tb-btn:hover { color: var(--fg); background: var(--bg-soft); border-color: var(--border-strong); }

/* --- content layout --- */
.content {
  padding: 28px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  align-items: start;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}
.col-main { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.col-side { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 112px; min-width: 0; }

.page-h {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: -6px;
}
.page-h h1 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0;
}
.page-h-sub {
  color: var(--fg-muted);
  font-size: 13.5px;
  margin-top: 4px;
}
.page-h-meta {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--fg-subtle);
}

/* --- KPI cards --- */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.kpi {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.kpi.highlight {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 8%, var(--bg)), var(--bg));
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}
.kpi-label {
  font-size: 12.5px;
  color: var(--fg-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.kpi-help {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  color: var(--fg-subtle);
  font-size: 10px;
  font-weight: 600;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  cursor: help;
}
.kpi-help:hover { color: var(--fg); border-color: var(--fg-muted); }
.kpi-val {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.018em;
  line-height: 1.1;
  margin-top: 2px;
}
.kpi-cap {
  font-size: 12px;
  color: var(--fg-subtle);
  margin-top: -2px;
}
.kpi-deltas {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 10px;
  font-size: 12px;
  font-family: var(--font-mono);
}
.kpi-delta {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  column-gap: 8px;
  row-gap: 1px;
  color: var(--fg-muted);
}
.kpi-delta .lbl { color: var(--fg-subtle); min-width: 0; white-space: nowrap; }
.kpi-delta .val { font-weight: 600; white-space: nowrap; text-align: right; }
.kpi-delta > span:last-child:not(.val) {
  grid-column: 1 / -1;
  color: var(--fg-subtle);
}
.kpi-delta.up .val { color: var(--pos); }
.kpi-delta.down .val { color: var(--neg); }
.kpi-delta.flat .val { color: var(--fg-muted); }

/* --- card primitive --- */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.card-h {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 20px 4px;
}
.card-h h2 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}
.card-h-sub {
  font-size: 12.5px;
  color: var(--fg-muted);
  margin-top: 3px;
}
.card-h-meta {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--fg-subtle);
}
.card-body { padding: 14px 20px 20px; }

/* --- waterfall --- */
.waterfall {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}
.wf-row {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr) 130px;
  gap: 16px;
  align-items: center;
  padding: 6px 0;
}
.wf-label {
  font-size: 13.5px;
  color: var(--fg);
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.wf-label .sign {
  font-family: var(--font-mono);
  color: var(--fg-subtle);
  font-size: 12px;
  width: 10px;
  display: inline-block;
}
.wf-row.total .wf-label {
  font-weight: 600;
  font-size: 14px;
}
.wf-track {
  position: relative;
  height: 26px;
  border-radius: 4px;
  background: transparent;
}
.wf-bar {
  position: absolute;
  top: 4px;
  bottom: 4px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--bg);
  white-space: nowrap;
}
.wf-bar.pos { background: var(--pos); }
.wf-bar.neg { background: var(--neg); opacity: 0.85; }
.wf-bar.gross { background: color-mix(in srgb, var(--pos) 75%, var(--fg)); }
.wf-bar.net { background: var(--fg); color: var(--bg); }
.wf-row.divider .wf-track {
  border-top: 1px dashed var(--border-strong);
  height: 1px;
}
.wf-val {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--fg);
}
.wf-val .pct {
  color: var(--fg-subtle);
  font-size: 11px;
  margin-left: 6px;
}
.wf-row.total .wf-val { font-weight: 700; }

/* --- P&L table --- */
.pnl-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.pnl-table thead th {
  text-align: right;
  font-weight: 500;
  font-size: 11.5px;
  color: var(--fg-subtle);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.pnl-table thead th:first-child { text-align: left; }
.pnl-table tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--fg);
}
.pnl-table tbody td:first-child {
  text-align: left;
  font-family: var(--font-sans);
  color: var(--fg-muted);
}
.pnl-table tr.sub td:first-child { padding-left: 28px; }
.pnl-table tr.tot td { font-weight: 700; color: var(--fg); background: var(--bg-soft); }
.pnl-table tr.tot td:first-child { color: var(--fg); }
.pnl-table tr.net td { font-weight: 700; color: var(--fg); background: var(--bg-soft); border-top: 1px solid var(--border-strong); }
.pnl-table td .pct-pill {
  display: inline-block;
  font-size: 11px;
  color: var(--fg-subtle);
  margin-left: 6px;
}
.pnl-table td .delta {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  margin-left: 6px;
}
.pnl-table td.delta-up { color: var(--pos); }
.pnl-table td.delta-down { color: var(--neg); }
.pnl-table tr.expanded td:first-child::before { content: "▾  "; font-size: 9px; color: var(--fg-subtle); }
.pnl-table tr.collapsible td:first-child { cursor: pointer; }
.pnl-table tr.collapsible:not(.expanded) td:first-child::before { content: "▸  "; font-size: 9px; color: var(--fg-subtle); }

/* --- trend chart --- */
.trend-chart { width: 100%; height: 220px; }
.trend-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--fg-muted);
}
.trend-legend .lg {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.trend-legend .sw {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* --- forecast --- */
.forecast {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-top: 10px;
}
.fc-cell {
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  padding: 14px 14px 12px;
  background: var(--bg-soft);
}
.fc-cell.actual {
  border-style: solid;
  background: var(--bg);
}
.fc-month {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-subtle);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.fc-month .tag {
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 9.5px;
  letter-spacing: 0.05em;
}
.fc-month .tag.proj { background: var(--warn-soft); color: var(--warn); }
.fc-month .tag.act { background: var(--pos-soft); color: var(--pos); }
.fc-val {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.015em;
}
.fc-cap {
  font-size: 12px;
  color: var(--fg-subtle);
  margin-top: 2px;
}

/* --- profit vs cash --- */
.pvc {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 6px;
}
.pvc-block {
  padding: 16px;
  background: var(--bg-soft);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.pvc-label {
  font-size: 12.5px;
  color: var(--fg-muted);
  margin-bottom: 4px;
}
.pvc-val {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.015em;
}
.pvc-cap {
  font-size: 12px;
  color: var(--fg-subtle);
  margin-top: 6px;
  line-height: 1.45;
}
.pvc-explain {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--warn-soft);
  color: color-mix(in srgb, var(--warn) 85%, var(--fg));
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.45;
}
[data-theme="dark"] .pvc-explain { color: var(--fg); }

/* --- insights panel --- */
.insights-h {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 4px;
}
.insights-h h2 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-subtle);
  margin: 0;
  font-family: var(--font-mono);
}
.insights-h .ct {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-subtle);
}
.insight {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}
.insight.warn { border-left: 3px solid var(--warn); }
.insight.neg { border-left: 3px solid var(--neg); }
.insight.pos { border-left: 3px solid var(--pos); }
.insight-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-subtle);
}
.insight-tag.warn { color: var(--warn); }
.insight-tag.neg { color: var(--neg); }
.insight-tag.pos { color: var(--pos); }
.insight-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--fg);
}
.insight-body {
  font-size: 12.5px;
  color: var(--fg-muted);
  line-height: 1.5;
}
.insight-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.insight-action {
  background: var(--fg);
  color: var(--bg);
  border: 0;
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.insight-action.sec {
  background: transparent;
  color: var(--fg-muted);
  border: 1px solid var(--border);
}
.insight-action.sec:hover { color: var(--fg); border-color: var(--border-strong); }
.insight-dismiss {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: transparent;
  border: 0;
  color: var(--fg-subtle);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.insight-dismiss:hover { background: var(--bg-soft); color: var(--fg); }

/* mini txns inside insight */
.mini-tx {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-soft);
  border-radius: 6px;
  font-size: 12.5px;
}
.mini-tx + .mini-tx { margin-top: 6px; }
.mini-tx .src {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg-muted);
}
.mini-tx .desc { flex: 1; color: var(--fg); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-tx .amt { font-family: var(--font-mono); font-weight: 600; color: var(--fg); }

/* --- categorize cards --- */
.cat-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  background: var(--bg-soft);
  border-radius: 6px;
  font-size: 13px;
}
.cat-card + .cat-card { margin-top: 6px; }
.cat-card .desc { flex: 1; min-width: 0; }
.cat-card .desc-l { color: var(--fg); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-card .desc-s { color: var(--fg-subtle); font-size: 11px; font-family: var(--font-mono); }
.cat-card .suggest {
  font-size: 11.5px;
  font-family: var(--font-mono);
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.cat-card .suggest:hover { filter: brightness(0.95); }

/* --- source pills/dots inside dashboard --- */
.src-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 4px;
}
.src-stripe   { background: oklch(0.65 0.18 285); }
.src-paypal   { background: oklch(0.65 0.15 240); }
.src-wise     { background: oklch(0.7 0.16 145); }
.src-coinbase { background: oklch(0.7 0.16 60); }
.src-bank     { background: oklch(0.6 0.04 250); }

/* --- glossary popover --- */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 8px 10px;
  border-radius: 5px;
  font-size: 11.5px;
  line-height: 1.4;
  font-family: var(--font-sans);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  white-space: normal;
  width: 220px;
  text-align: left;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 80;
  box-shadow: var(--shadow);
}
[data-tip]:hover::after { opacity: 1; }

/* --- monthly review banner --- */
.review-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 12%, var(--bg)), var(--bg));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--fg);
}
.review-banner .star { color: var(--accent); font-size: 16px; }
.review-banner strong { color: var(--fg); }
.review-banner .review-cta {
  margin-left: auto;
  background: var(--fg);
  color: var(--bg);
  border: 0;
  padding: 6px 12px;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

/* --- popovers for period selector --- */
.popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 50;
  min-width: 200px;
  display: none;
}
.popover.open { display: block; }
.popover .pop-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 10px;
  border-radius: 5px;
  font-size: 13.5px;
  color: var(--fg);
  cursor: pointer;
}
.popover .pop-item:hover { background: var(--bg-soft); }
.popover .pop-item.on { background: var(--accent-soft); color: var(--fg); font-weight: 500; }
.popover .pop-item .sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-subtle);
}

/* --- responsive --- */

/* Below 1400px: insights drop under main column */
@media (max-width: 1400px) {
  .content { grid-template-columns: minmax(0, 1fr); }
  .col-side { position: static; }
  .tb-label { display: none; }
}

/* Below 1100px: hide sidebar, become full-bleed dashboard */
@media (max-width: 1100px) {
  :root { --side-w: 0px; }
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  .toolbar { padding: 12px 20px; }
}

/* Tablet */
@media (max-width: 840px) {
  .demobar { padding: 8px 14px; gap: 10px; font-size: 12px; }
  .demobar-tag { display: none; }
  .toolbar { padding: 10px 16px; gap: 8px; top: 38px; }
  .toolbar > * { font-size: 13px; }
  .content { padding: 18px; gap: 18px; }
  .page-h { flex-direction: column; align-items: flex-start; gap: 6px; }
  .page-h h1 { font-size: 22px; }
  .page-h-meta { display: none; }
  .review-banner { flex-wrap: wrap; gap: 10px; padding: 12px 14px; }
  .review-banner .review-cta { width: 100%; padding: 9px 12px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 14px 14px 12px; }
  .kpi-val { font-size: 24px; }
  .forecast { grid-template-columns: 1fr; }
  .pvc { grid-template-columns: 1fr; }
  .card-h { padding: 16px 16px 4px; }
  .card-body { padding: 12px 16px 18px; }
  .wf-row { grid-template-columns: 1fr; gap: 4px; padding: 10px 0; }
  .wf-row.divider { padding: 0; }
  .wf-label { font-size: 14px; }
  .wf-track { height: 22px; }
  .wf-bar { font-size: 10.5px; padding: 0 6px; }
  .wf-val { text-align: left; font-size: 12.5px; }
  .pnl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .pnl-table { min-width: 540px; }
  .insight-action { padding: 8px 12px; font-size: 13px; }
  .tb-btn, .tb-period { padding: 9px 13px; }
  .tb-compare button { padding: 9px 13px; }
}

/* Phone */
@media (max-width: 540px) {
  .demobar { padding: 7px 12px; }
  .demobar-l { gap: 8px; }
  .demobar-cta { font-size: 12px; padding: 6px 10px; }
  .toolbar { padding: 10px 14px; }
  .tb-right { display: none; }
  .tb-compare button { padding: 9px 10px; font-size: 12.5px; }
  .content { padding: 14px; gap: 14px; }
  .page-h h1 { font-size: 20px; }
  .kpis { grid-template-columns: 1fr; }
  .kpi-val { font-size: 26px; }
  .review-banner { font-size: 13px; }
  .insight { padding: 12px; }
  .insight-title { font-size: 13.5px; }
  .insight-body { font-size: 12px; }
  .card-h h2 { font-size: 15px; }
  .pnl-table { min-width: 480px; font-size: 12.5px; }
  .trend-chart { height: 180px; }
}

/* ============================================================
   SHARED DEMO UI — toasts, dialogs, dropdown menus
   ============================================================ */

/* --- toasts --- */
#demo-toasts {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
  pointer-events: none;
}
.demo-toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 240px;
  max-width: 360px;
  padding: 12px 14px;
  background: var(--fg);
  color: var(--bg);
  border-radius: 9px;
  box-shadow: 0 10px 30px -8px rgba(0,0,0,0.4), 0 2px 8px rgba(0,0,0,0.18);
  font-size: 13px;
  line-height: 1.45;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.2,0.8,0.2,1);
}
.demo-toast.in { opacity: 1; transform: translateY(0) scale(1); }
.demo-toast .t-ico {
  flex: none;
  width: 18px; height: 18px;
  display: grid; place-items: center;
  font-family: var(--font-mono);
  font-size: 12px; font-weight: 700;
  border-radius: 50%;
  margin-top: 1px;
}
.demo-toast.ok .t-ico    { background: var(--pos); color: #fff; }
.demo-toast.info .t-ico  { background: color-mix(in srgb, var(--bg) 22%, transparent); color: var(--bg); }
.demo-toast.warn .t-ico  { background: var(--warn); color: #1a1206; }
.demo-toast.neg .t-ico   { background: var(--neg); color: #fff; }
.demo-toast .t-body { min-width: 0; }
.demo-toast .t-title { font-weight: 600; }
.demo-toast .t-sub { opacity: 0.78; font-size: 12px; margin-top: 1px; }

/* --- dialog (modal) --- */
.demo-overlay {
  position: fixed; inset: 0; z-index: 150;
  background: color-mix(in srgb, #000 48%, transparent);
  backdrop-filter: blur(2px);
  display: grid; place-items: center;
  padding: 24px;
  opacity: 0; transition: opacity 0.18s ease;
}
.demo-overlay.in { opacity: 1; }
.demo-dialog {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 60px -16px rgba(0,0,0,0.5);
  width: 100%;
  max-width: 440px;
  max-height: calc(100vh - 48px);
  overflow: auto;
  transform: translateY(10px) scale(0.985);
  transition: transform 0.2s cubic-bezier(0.2,0.8,0.2,1);
}
.demo-overlay.in .demo-dialog { transform: none; }
.demo-dialog.wide { max-width: 600px; }
.demo-dialog-h {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
  padding: 20px 22px 0;
}
.demo-dialog-h h3 { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
.demo-dialog-h .sub { font-size: 13px; color: var(--fg-muted); margin-top: 4px; line-height: 1.45; }
.demo-dialog-x {
  flex: none; width: 28px; height: 28px; border-radius: 7px;
  background: transparent; border: 0; color: var(--fg-subtle);
  font-size: 18px; line-height: 1; cursor: pointer; display: grid; place-items: center;
}
.demo-dialog-x:hover { background: var(--bg-soft); color: var(--fg); }
.demo-dialog-body { padding: 16px 22px; font-size: 13.5px; color: var(--fg-muted); line-height: 1.55; }
.demo-dialog-body strong { color: var(--fg); }
.demo-dialog-foot {
  display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap;
  padding: 4px 22px 22px;
}
.demo-btn {
  padding: 9px 15px; border-radius: 7px; font-size: 13.5px; font-weight: 500;
  border: 1px solid var(--border); background: var(--bg-soft); color: var(--fg); cursor: pointer;
}
.demo-btn:hover { border-color: var(--border-strong); }
.demo-btn.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.demo-btn.primary:hover { opacity: 0.9; }
.demo-btn.danger { background: var(--neg); color: #fff; border-color: var(--neg); }
.demo-btn.danger:hover { opacity: 0.9; }

/* dialog inner helpers */
.demo-opt-list { display: flex; flex-direction: column; gap: 8px; }
.demo-opt {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 9px;
  cursor: pointer; background: var(--bg); text-align: left; width: 100%;
  font-size: 14px; color: var(--fg); transition: border-color 0.12s, background 0.12s;
}
.demo-opt:hover { border-color: var(--accent); background: var(--bg-soft); }
.demo-opt .o-ico {
  flex: none; width: 30px; height: 30px; border-radius: 7px;
  background: var(--bg-sunk); display: grid; place-items: center;
  font-family: var(--font-mono); font-size: 13px; color: var(--fg-muted);
}
.demo-opt .o-body { min-width: 0; }
.demo-opt .o-sub { font-size: 12px; color: var(--fg-subtle); margin-top: 1px; }
.demo-cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.demo-cat-grid button {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--fg); font-size: 13px; cursor: pointer; text-align: left;
}
.demo-cat-grid button:hover { border-color: var(--accent); background: var(--bg-soft); }
.demo-field-input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--bg); color: var(--fg); font-family: var(--font-sans); font-size: 14px;
}
.demo-field-input:focus { outline: none; border-color: var(--accent); }

/* --- dropdown menu (popover under a control) --- */
.demo-menu {
  position: absolute; z-index: 90;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow);
  padding: 6px;
  min-width: 200px;
  font-size: 13.5px;
  opacity: 0; transform: translateY(-4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.demo-menu.in { opacity: 1; transform: none; }
.demo-menu-label {
  font-family: var(--font-mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--fg-subtle); padding: 6px 10px 4px;
}
.demo-menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 6px; cursor: pointer; color: var(--fg);
  user-select: none;
}
.demo-menu-item:hover { background: var(--bg-soft); }
.demo-menu-item .mk {
  flex: none; width: 15px; height: 15px; border-radius: 4px;
  border: 1.5px solid var(--border-strong); display: grid; place-items: center;
}
.demo-menu-item.on .mk { background: var(--accent); border-color: var(--accent); }
.demo-menu-item.on .mk::after {
  content: ""; width: 8px; height: 4px; margin-top: -1px;
  border-left: 1.5px solid var(--accent-fg); border-bottom: 1.5px solid var(--accent-fg);
  transform: rotate(-45deg);
}
.demo-menu-item .dot { flex: none; }
.demo-menu-item.sel { background: var(--accent-soft); font-weight: 500; }
.demo-menu-item .sub { margin-left: auto; font-family: var(--font-mono); font-size: 11px; color: var(--fg-subtle); }
.demo-menu-sep { height: 1px; background: var(--border); margin: 5px 4px; }

/* a row fading out (used by send-reminder, exclude, etc.) */
.demo-faded { opacity: 0.45; }
.demo-strike .tx-desc, .demo-strike td { text-decoration: line-through; }
.tx-amt.demo-excluded { text-decoration: line-through; opacity: 0.5; }

/* small inline "sent" pill */
.sent-pill {
  font-family: var(--font-mono); font-size: 11px; color: var(--pos);
  display: inline-flex; align-items: center; gap: 4px;
}

/* highlight pulse for "edit assumptions" etc. */
@keyframes demoHi { 0%,100% { box-shadow: 0 0 0 0 transparent; } 30% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 40%, transparent); } }
.demo-pulse { animation: demoHi 1.1s ease; border-color: var(--accent) !important; }

/* selected alternative category (categorize) */
.alt-btn.sel { background: var(--accent-soft) !important; color: var(--accent) !important; border-color: var(--accent) !important; }
