.view-switch {
  flex: 0 0 auto;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-top: 9px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: color-mix(in oklch, var(--panel-raised) 62%, transparent);
}

.view-switch button {
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 25px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 10px;
  font-weight: 760;
  cursor: pointer;
}

.view-switch button:hover { color: var(--ink); }
.view-switch button[aria-selected="true"] {
  background: var(--control-active);
  color: var(--control-active-ink);
}

.balance-toolbar {
  grid-template-columns: 180px minmax(520px, 0.95fr) minmax(600px, 1.15fr);
}

.balance-toolbar .filter-frame { flex-wrap: nowrap; }
.balance-toolbar .filter-frame:first-child { justify-content: center; }
.balance-toolbar .filter-frame:nth-child(2) {
  justify-content: center;
  gap: 24px;
}
.balance-toolbar .filter-frame:last-child {
  justify-content: flex-start;
  gap: 10px;
}

.balance-dashboard {
  --balance-row-height: clamp(21px, calc((100dvh - 405px) / 14), 29.5px);
  position: relative;
  min-height: 0;
  overflow: auto;
  padding: 12px 16px 22px;
  background:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px),
    var(--bg);
  background-size: 48px 48px;
  scrollbar-color: var(--line-strong) transparent;
}

.balance-canvas {
  width: max-content;
  min-width: 100%;
  display: grid;
  gap: 10px;
}

.balance-section,
.reconciliation-section,
.balance-state {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: color-mix(in oklch, var(--panel) 96%, transparent);
  box-shadow: 0 10px 30px color-mix(in oklch, var(--shadow) 42%, transparent);
}

.balance-section-header {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
}

.balance-section-title {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.balance-section-title-line {
  display: flex;
  align-items: center;
  gap: 6px;
}

.balance-info-button {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid color-mix(in oklch, var(--accent) 58%, var(--line));
  border-radius: 50%;
  background: color-mix(in oklch, var(--accent) 8%, transparent);
  color: var(--accent-ink);
  font: 800 10px/1 Georgia, serif;
  cursor: pointer;
}

.balance-info-button:hover,
.balance-info-button[aria-expanded="true"] {
  border-color: var(--accent);
  background: color-mix(in oklch, var(--accent) 18%, var(--panel));
}

.balance-info-popover {
  position: fixed;
  z-index: 80;
  width: min(370px, calc(100vw - 24px));
  padding: 12px 14px;
  border: 1px solid color-mix(in oklch, var(--accent) 54%, var(--line-strong));
  border-radius: 8px;
  background: color-mix(in oklch, var(--panel-raised) 98%, transparent);
  box-shadow: 0 18px 50px color-mix(in oklch, var(--shadow) 64%, transparent);
  color: var(--ink);
}

.balance-info-popover[hidden] { display: none; }
.balance-info-popover strong { display: block; margin-bottom: 5px; font-size: 12px; }
.balance-info-popover p { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.45; }

.balance-freshness {
  color: var(--quiet);
  font-size: 9px;
  line-height: 1.35;
}
.balance-freshness { text-align: right; }

.balance-table-wrap {
  width: 100%;
  max-width: calc(100dvw - 64px);
  overflow-x: auto;
  scrollbar-color: var(--line-strong) transparent;
}

.balance-date-rail {
  position: sticky;
  top: 0;
  z-index: 12;
  width: 100%;
  max-width: calc(100dvw - 64px);
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel-raised);
  box-shadow: 0 10px 24px color-mix(in oklch, var(--shadow) 46%, transparent);
  scrollbar-width: none;
}

.balance-date-rail::-webkit-scrollbar { display: none; }
.balance-date-table thead th {
  position: static;
  font-size: 11px;
  font-weight: 880;
}
.balance-date-table .name-column { color: var(--accent-ink); }

.balance-table {
  width: 100%;
  min-width: 1040px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  font-variant-numeric: tabular-nums;
}

.balance-table th,
.balance-table td {
  height: var(--balance-row-height);
  padding: 0 9px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  text-align: right;
  font-size: 10px;
}

.balance-table tr:last-child td { border-bottom: 0; }
.balance-table th:last-child,
.balance-table td:last-child { border-right: 0; }

.balance-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  height: 36px;
  background: var(--panel-raised);
  color: var(--muted);
  font-size: 9px;
  font-weight: 780;
}

.balance-table .name-column {
  position: sticky;
  left: 0;
  z-index: 2;
  width: 260px;
  min-width: 260px;
  max-width: 260px;
  text-align: left;
  background: var(--panel);
}

.balance-table thead .name-column {
  z-index: 4;
  background: var(--panel-raised);
}

.balance-table .amount-column {
  width: 91px;
  min-width: 91px;
}

.balance-amount-trigger {
  width: calc(100% + 18px);
  min-height: var(--balance-row-height);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin: 0 -9px;
  padding: 0 9px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-variant-numeric: inherit;
  font-weight: inherit;
  cursor: pointer;
  transform: scale(1);
  transition: color 120ms var(--ease-out), background-color 120ms var(--ease-out), transform 120ms var(--ease-out);
}

.balance-amount-trigger:hover,
.balance-amount-trigger:focus-visible {
  background: color-mix(in oklch, var(--accent) 10%, transparent);
  color: var(--accent-ink);
}

.balance-amount-trigger:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.balance-amount-trigger:active { transform: scale(0.96); }

.balance-table .current-column {
  width: 112px;
  min-width: 112px;
  background: color-mix(in oklch, var(--accent) 7%, var(--panel));
}

.balance-table thead .current-column {
  background: color-mix(in oklch, var(--accent) 13%, var(--panel-raised));
  color: var(--accent-ink);
}

.balance-table .future-column {
  color: var(--quiet);
  background: color-mix(in oklch, var(--panel) 78%, transparent);
}

.balance-table .group-row td {
  height: var(--balance-row-height);
  background: var(--bg-deep);
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.balance-table .group-row .name-column { background: var(--bg-deep); }

.balance-table .group-row.is-collapsible td {
  color: var(--ink);
  font-size: 10px;
  font-weight: 780;
  letter-spacing: 0;
  text-transform: none;
}

.balance-group-toggle {
  display: flex;
  align-items: center;
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.balance-group-toggle:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
}

.balance-group-chevron {
  flex: 0 0 auto;
  width: 16px;
  color: var(--accent-ink);
  font-size: 16px;
  line-height: 1;
  transform: rotate(0deg);
  transition: transform 140ms ease;
}

.balance-group-toggle[aria-expanded="true"] .balance-group-chevron { transform: rotate(90deg); }

.balance-group-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.balance-group-count {
  flex: 0 0 auto;
  margin-left: 7px;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--quiet);
  font-size: 8px;
}

.balance-detail-row[hidden] { display: none; }

.module-tree-row .name-column {
  padding-left: calc(9px + var(--tree-depth, 0) * 15px);
}

.balance-tree-toggle,
.balance-tree-leaf {
  display: flex;
  align-items: center;
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
}

.balance-tree-toggle { cursor: pointer; }

.balance-tree-toggle:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
}

.balance-tree-toggle[aria-expanded="true"] .balance-group-chevron { transform: rotate(90deg); }

.balance-tree-spacer {
  flex: 0 0 auto;
  width: 16px;
}

.balance-tree-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.balance-module-code {
  margin-left: 4px;
  color: var(--quiet);
  font-size: 8px;
}

.balance-module-status {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 6px;
  padding: 1px 5px 1px 4px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px currentColor;
  font-size: 7px;
  font-weight: 760;
  line-height: 1.4;
  vertical-align: 1px;
}

.balance-module-status-dot {
  width: 4px;
  height: 4px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: currentColor;
}

.balance-module-status.is-active {
  color: color-mix(in oklch, var(--pastel-mint) 78%, var(--ink));
  background: color-mix(in oklch, var(--pastel-mint) 9%, transparent);
}

.balance-module-status.is-inactive {
  color: color-mix(in oklch, var(--pastel-coral) 68%, var(--muted));
  background: color-mix(in oklch, var(--pastel-coral) 7%, transparent);
}

.balance-table .standalone-module-row td {
  background: color-mix(in oklch, var(--accent) 9%, var(--panel));
  font-weight: 800;
}

.balance-table .standalone-module-row .name-column {
  background: color-mix(in oklch, var(--accent) 9%, var(--panel));
}

.balance-table .money-in-transit-row td {
  background: color-mix(in oklch, var(--accent) 8%, var(--panel-raised));
  border-top-color: color-mix(in oklch, var(--accent) 34%, var(--line-strong));
  color: var(--ink);
  font-weight: 860;
}

.balance-table .money-in-transit-row .name-column {
  background: color-mix(in oklch, var(--accent) 8%, var(--panel-raised));
}

.balance-table .money-in-transit-row .balance-group-label {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.015em;
}

.balance-table .money-in-transit-route-row .name-column {
  padding-left: 29px;
}

.balance-table .money-in-transit-route-row .balance-row-name span:first-child {
  color: var(--ink);
  font-weight: 680;
}

.balance-table .total-row td {
  height: var(--balance-row-height);
  background: color-mix(in oklch, var(--accent) 6%, var(--panel-raised));
  color: var(--ink);
  font-weight: 820;
}
.balance-table .total-row .name-column {
  background: color-mix(in oklch, var(--accent) 6%, var(--panel-raised));
}

.reconciliation-table .total-row .name-column {
  white-space: normal;
  line-height: 1.18;
}

.balance-row-name {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.balance-row-name span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.balance-kind {
  flex: 0 0 auto;
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--quiet);
  font-size: 7px;
  font-weight: 800;
  text-transform: uppercase;
}

.balance-negative { color: var(--pastel-coral); }
.balance-zero { color: var(--quiet); }
.balance-table .group-row td.balance-negative,
.balance-table .total-row td.balance-negative { color: var(--pastel-coral); }

.reconciliation-section {
  overflow: hidden;
  border-color: color-mix(in oklch, var(--accent) 36%, var(--line-strong));
}

.reconciliation-section .balance-section-header {
  background: color-mix(in oklch, var(--accent) 5%, transparent);
}

.reconciliation-table .delta-row td {
  height: var(--balance-row-height);
  font-size: 11px;
  font-weight: 850;
}

.reconciliation-table .delta-row .name-column {
  color: var(--accent-ink);
}

.reconciliation-status {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  width: 100%;
}

.reconciliation-mark {
  width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 900;
}

.reconciliation-status.is-ok { color: var(--pastel-mint); }
.reconciliation-status.is-ok .reconciliation-mark {
  border: 1px solid color-mix(in oklch, var(--pastel-mint) 62%, transparent);
  background: color-mix(in oklch, var(--pastel-mint) 14%, transparent);
}
.reconciliation-status.is-error { color: var(--pastel-coral); }
.reconciliation-status.is-error .reconciliation-value { color: var(--ink); }
.reconciliation-status.is-error .reconciliation-value.is-negative {
  color: color-mix(in oklch, var(--pastel-coral) 78%, var(--ink));
}
.reconciliation-status.is-error .reconciliation-mark {
  border: 1px solid color-mix(in oklch, var(--pastel-coral) 62%, transparent);
  background: color-mix(in oklch, var(--pastel-coral) 14%, transparent);
}
.reconciliation-status.is-pending { color: var(--quiet); }

.app.is-balance-view #headlineValue { color: var(--ink); }
.app.is-balance-view #headlineValue.balance-delta-negative {
  color: color-mix(in oklch, var(--pastel-coral) 78%, var(--ink));
}
.app.is-balance-view #headlineValue.balance-delta-zero { color: var(--pastel-mint); }

.balance-detail-popover {
  position: fixed;
  z-index: 40;
  width: min(380px, calc(100dvw - 24px));
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--tooltip-bg);
  box-shadow: 0 18px 44px color-mix(in oklch, var(--shadow) 84%, transparent);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 140ms var(--ease-out), transform 140ms var(--ease-out);
}

.balance-detail-popover.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.balance-detail-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.balance-detail-close {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  margin: -8px -8px 0 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  transform: scale(1);
  transition: color 120ms var(--ease-out), background-color 120ms var(--ease-out), transform 120ms var(--ease-out);
}

.balance-detail-close:hover,
.balance-detail-close:focus-visible {
  background: color-mix(in oklch, var(--accent) 10%, transparent);
  color: var(--ink);
}

.balance-detail-close:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.balance-detail-close:active { transform: scale(0.96); }

.balance-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-top: 10px;
}

.balance-detail-metric {
  min-width: 0;
  border: 0;
  padding: 9px 10px;
  border-radius: 6px;
  background: color-mix(in oklch, var(--panel-raised) 76%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in oklch, var(--line) 76%, transparent);
  color: inherit;
  font: inherit;
  text-align: left;
}

.balance-detail-metric span {
  display: block;
  min-height: 2.5em;
  color: var(--muted);
  font-size: 8px;
  font-weight: 740;
  line-height: 1.25;
}

.balance-detail-metric strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.balance-detail-metric em {
  display: block;
  margin-top: 4px;
  color: var(--quiet);
  font-size: 7px;
  font-style: normal;
  font-weight: 720;
  letter-spacing: .01em;
}

.balance-detail-metric.is-drillable {
  cursor: pointer;
  transition: background-color 120ms var(--ease-out), box-shadow 120ms var(--ease-out), transform 120ms var(--ease-out);
}

.balance-detail-metric.is-drillable:hover,
.balance-detail-metric.is-drillable:focus-visible {
  background: color-mix(in oklch, var(--accent) 10%, var(--panel-raised));
  box-shadow: inset 0 0 0 1px color-mix(in oklch, var(--accent) 66%, var(--line));
}

.balance-detail-metric.is-drillable:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.balance-detail-metric.is-drillable:active { transform: scale(.985); }

.balance-detail-metric.is-inflow strong { color: var(--pastel-mint); }
.balance-detail-metric.is-outflow strong { color: var(--pastel-coral); }
.balance-detail-metric.is-negative strong { color: var(--pastel-coral); }
.balance-detail-metric.is-closing {
  background: color-mix(in oklch, var(--accent) 10%, var(--panel-raised));
}

.balance-detail-formula {
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--quiet);
  font-size: 8px;
  line-height: 1.35;
}

.balance-state {
  min-height: 280px;
  display: grid;
  place-items: center;
  padding: 36px;
  text-align: center;
}

.balance-state strong {
  display: block;
  margin-bottom: 7px;
  font-size: 15px;
}

.balance-state span {
  max-width: 52em;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.balance-loading-state {
  min-width: min(720px, calc(100dvw - 64px));
  align-content: center;
  gap: 18px;
}

.balance-loading-copy {
  display: grid;
  justify-items: center;
  gap: 2px;
}

.balance-loading-stage-meta,
.balance-loading-meta {
  width: min(560px, calc(100dvw - 112px));
  display: flex;
  justify-content: space-between;
  gap: 18px;
  color: var(--quiet);
  font-size: 9px;
  font-variant-numeric: tabular-nums;
}

.balance-loading-stage-meta { margin-top: 7px; }

.balance-loading-progress {
  width: min(560px, calc(100dvw - 112px));
  height: 6px;
}

.balance-loading-meta { margin-top: -4px; }

.balance-footer[hidden],
.balance-dashboard[hidden],
.balance-toolbar[hidden],
.map-toolbar[hidden],
.map-footer[hidden],
.stage[hidden] { display: none !important; }

.balance-footer .source-note { margin-left: auto; }

@media (max-width: 980px) {
  .balance-toolbar { grid-template-columns: 1fr; }
  .balance-toolbar .filter-frame { flex-wrap: wrap; }
  .balance-table-wrap { max-width: calc(100vw - 20px); }
  .balance-dashboard { padding-inline: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .view-switch button { transition: none; }
  .balance-loading-progress .auth-progress-fill { transition: none; }
  .balance-detail-popover,
  .balance-amount-trigger,
  .balance-detail-close { transition: none; }
}
