.moneyflow-shell {
  width: min(1520px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.moneyflow-toolbar {
  display: flex;
  align-items: end;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.moneyflow-toolbar .toolbar-field:first-child {
  width: 180px;
}

.moneyflow-toolbar .toolbar-field:nth-child(2) {
  width: 160px;
}

.moneyflow-toolbar button {
  min-height: 40px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0 14px;
  color: var(--accent);
  background: var(--surface);
  font-weight: 800;
  cursor: pointer;
}

.moneyflow-toolbar button:hover:not(:disabled) {
  color: #fff;
  background: var(--accent);
}

.moneyflow-toolbar button:disabled {
  opacity: .55;
  cursor: default;
}

.moneyflow-status {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.moneyflow-status > div {
  min-width: 0;
  display: grid;
  gap: 4px;
  padding: 14px 16px;
}

.moneyflow-status > div + div {
  border-left: 1px solid var(--line);
}

.moneyflow-status span,
.moneyflow-status small,
.flow-metric-band span,
.flow-metric-band small {
  color: var(--muted);
  font-size: 12px;
}

.moneyflow-status strong {
  font-size: 18px;
}

.moneyflow-content {
  min-height: 520px;
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.flow-section + .flow-section {
  border-top: 12px solid var(--bg);
}

.flow-heading,
.flow-section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
}

.flow-heading {
  align-items: flex-start;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.flow-heading h2,
.flow-heading p,
.flow-section-heading h3,
.flow-section-heading span {
  margin: 0;
}

.flow-heading h2 {
  font-size: 19px;
}

.flow-heading p,
.flow-section-heading span {
  color: var(--muted);
  font-size: 12px;
}

.flow-heading p {
  margin-top: 5px;
  line-height: 1.6;
}

.flow-heading > strong {
  color: var(--accent);
  font-size: 13px;
}

.flow-metric-band {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: #fbfcfb;
}

.flow-metric-band > div {
  min-width: 0;
  display: grid;
  gap: 5px;
  padding: 14px 16px;
}

.flow-metric-band > div + div {
  border-left: 1px solid var(--line);
}

.flow-metric-band strong {
  font-size: 20px;
  line-height: 1.2;
}

.positive { color: var(--market-up); }
.negative { color: var(--market-down); }

.flow-section-heading {
  padding: 16px 18px 10px;
}

.flow-section-heading h3 {
  font-size: 15px;
}

.flow-chart {
  display: flex;
  align-items: end;
  gap: 6px;
  height: 180px;
  padding: 18px 18px 12px;
  border-top: 1px solid var(--line);
  overflow-x: auto;
}

.flow-chart-item {
  flex: 1 0 24px;
  display: flex;
  min-width: 24px;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: end;
  gap: 7px;
}

.flow-chart-item span {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.flow-chart-bar {
  width: min(22px, 100%);
  min-height: 5px;
  border-radius: 3px 3px 0 0;
  background: var(--line);
}

.flow-chart-bar.positive { background: var(--market-up); }
.flow-chart-bar.negative { background: var(--market-down); }

.flow-two-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
}

.flow-table-panel { min-width: 0; background: var(--surface); }
.flow-table-wrap { width: 100%; overflow: auto; }
.flow-table { width: 100%; min-width: 680px; border-collapse: collapse; }

.flow-table th,
.flow-table td {
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.flow-table th {
  color: var(--muted);
  background: var(--surface-2);
  font-size: 12px;
}

.flow-table .numeric { text-align: right; font-variant-numeric: tabular-nums; }
.flow-table td > strong,
.flow-table td > small { display: block; }
.flow-table td > small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.flow-rank { width: 48px; color: var(--muted); font-variant-numeric: tabular-nums; }

.heatmap-wrap {
  max-height: min(72vh, 860px);
  border-top: 1px solid var(--line);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
.heatmap {
  width: 100%;
  min-width: max(760px, calc(124px + var(--heatmap-days, 20) * 28px));
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}
.heatmap th,
.heatmap td { border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.heatmap thead th {
  position: sticky;
  z-index: 2;
  top: 0;
  height: 28px;
  padding: 5px 3px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 9px;
  font-weight: 800;
}
.heatmap thead th:first-child {
  z-index: 4;
  left: 0;
  width: 124px;
  border-left: 0;
  text-align: left;
}
.heatmap tbody th {
  position: sticky;
  z-index: 1;
  left: 0;
  width: 124px;
  padding: 4px 8px;
  background: var(--surface);
  text-align: left;
}
.heatmap tbody th strong,
.heatmap tbody th small { display: block; }
.heatmap tbody th strong { overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.heatmap tbody th small { margin-top: 1px; color: var(--muted); font-size: 8px; font-weight: 400; }
.heatmap td { height: 24px; padding: 0; text-align: center; font-size: 8px; }
.heat-positive { background: #c96860; }
.heat-negative { background: #70a99d; }
.heat-neutral { background: var(--surface-2); }
.heat-level-1 { opacity: .35; }
.heat-level-2 { opacity: .48; }
.heat-level-3 { opacity: .62; }
.heat-level-4 { opacity: .78; }
.heat-level-5 { opacity: .95; }
.heat-legend { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.heat-legend i { width: 14px; height: 14px; display: inline-block; border-radius: 2px; }
.heatmap-meta { display: flex; align-items: center; gap: 14px; }
.heatmap-meta > strong { color: var(--accent); font-size: 12px; white-space: nowrap; }

.flow-regime { display: inline-flex; align-items: center; min-height: 24px; border: 1px solid var(--line); border-radius: 4px; padding: 2px 8px; font-size: 12px; font-weight: 800; }
.flow-regime-strong { border-color: #e4c6c2; color: var(--market-up); background: var(--red-soft); }
.flow-regime-weak { border-color: #bcd7d0; color: var(--market-down); background: var(--accent-soft); }
.flow-regime-neutral { border-color: #e5d3ae; color: var(--gold); background: var(--gold-soft); }
.flow-regime-missing { color: var(--muted); background: var(--surface-2); }

.flow-path { display: grid; grid-template-columns: 180px 1fr; gap: 18px; padding: 18px; }
.path-root { display: grid; align-content: center; gap: 7px; min-height: 80px; border: 1px solid var(--accent); border-radius: 6px; padding: 16px; color: var(--accent); background: var(--accent-soft); }
.path-root span { font-size: 12px; }
.path-root strong { font-size: 20px; }
.path-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.path-item { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 9px; min-width: 0; border: 1px solid var(--line); border-radius: 5px; padding: 10px 12px; }
.path-item > b { color: var(--muted); font-size: 12px; }
.path-item strong,
.path-item span { display: block; }
.path-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.path-item span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.path-item em { font-style: normal; font-size: 13px; font-variant-numeric: tabular-nums; }

.flow-method { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border-top: 1px solid var(--line); background: #fbfcfb; }
.flow-method > div { min-width: 0; padding: 15px 18px; }
.flow-method > div + div { border-left: 1px solid var(--line); }
.flow-method strong,
.flow-method span { display: block; }
.flow-method strong { margin-bottom: 5px; font-size: 13px; }
.flow-method span { color: var(--muted); font-size: 12px; line-height: 1.6; }

.flow-empty,
.flow-error { padding: 48px 16px; color: var(--muted); text-align: center; }
.flow-error { color: var(--market-down); }

@media (max-width: 1100px) {
  .flow-metric-band { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .flow-metric-band > div:nth-child(4) { border-left: 0; }
  .flow-metric-band > div:nth-child(n + 4) { border-top: 1px solid var(--line); }
  .flow-method { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .flow-method > div:nth-child(4) { border-left: 0; }
  .flow-method > div:nth-child(n + 4) { border-top: 1px solid var(--line); }
}

@media (max-width: 760px) {
  .moneyflow-shell { padding: 10px; }
  .moneyflow-toolbar { align-items: stretch; flex-wrap: wrap; }
  .moneyflow-toolbar .toolbar-field:first-child,
  .moneyflow-toolbar .toolbar-field:nth-child(2) { width: calc(50% - 6px); }
  .moneyflow-toolbar button { width: 100%; }
  .moneyflow-status { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .moneyflow-status > div:nth-child(3) { border-left: 0; }
  .moneyflow-status > div:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .flow-two-columns { grid-template-columns: 1fr; }
  .flow-path { grid-template-columns: 1fr; }
  .path-list { grid-template-columns: 1fr; }
  .flow-method { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .flow-method > div:nth-child(3) { border-left: 0; }
  .flow-method > div:nth-child(n + 3) { border-top: 1px solid var(--line); }
}

@media (max-width: 500px) {
  .moneyflow-toolbar .toolbar-field:first-child,
  .moneyflow-toolbar .toolbar-field:nth-child(2),
  .moneyflow-status,
  .flow-metric-band,
  .flow-method { width: 100%; grid-template-columns: 1fr; }
  .moneyflow-status > div + div,
  .flow-metric-band > div + div,
  .flow-method > div + div { border-top: 1px solid var(--line); border-left: 0; }
  .flow-heading,
  .flow-section-heading { align-items: flex-start; flex-direction: column; }
  .heatmap-meta { width: 100%; justify-content: space-between; }
}
