:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --panel: #ffffff;
  --panel-soft: #f1f4f8;
  --ink: #1b2430;
  --muted: #657181;
  --line: #d9dee6;
  --accent: #0f766e;
  --accent-strong: #0a5c55;
  --gold: #b7791f;
  --danger: #b42318;
  --blue: #2457a6;
  --radius: 4px;
  --shadow: 0 8px 22px rgba(31, 42, 55, 0.07);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 13.33px;
  font-weight: 700;
  min-height: 34px;
  padding: 0 12px;
}

button:hover {
  background: var(--accent-strong);
}

button.secondary {
  background: #e6ecef;
  color: var(--ink);
}

button.secondary:hover {
  background: #d8e0e4;
}

button:disabled,
button:disabled:hover {
  background: #edf1f3;
  color: #9aa5af;
  cursor: not-allowed;
}

button.small {
  min-height: 28px;
  padding: 0 9px;
}

.shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #17202b;
  color: #eef4f2;
  padding: 24px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}

.mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--accent);
  font-weight: 900;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.brand p,
.eyebrow,
.muted,
small {
  color: var(--muted);
}

.brand p {
  margin: 2px 0 0;
  color: #aebbc8;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  justify-content: flex-start;
  width: 100%;
  background: transparent;
  color: #dbe5ec;
  text-align: left;
  font-weight: 650;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.1);
}

.main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.topbar h2 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 13px;
  text-transform: uppercase;
}

.top-actions,
.filters,
.button-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.top-actions[hidden] {
  display: none;
}

.compact-actions {
  flex-wrap: nowrap;
  gap: 6px;
}

.split-lines {
  display: grid;
  gap: 10px;
  margin: 14px 0;
}

.split-line {
  display: grid;
  grid-template-columns: minmax(120px, 170px) minmax(220px, 1fr) minmax(240px, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.split-line-result {
  min-height: 35px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-content: center;
  column-gap: 8px;
  padding-left: 10px;
  border-left: 2px solid var(--line);
  font-size: 12px;
}

.split-line-result span,
.split-line-result small {
  color: var(--muted);
}

.split-line-result small {
  grid-column: 1 / -1;
}

.selected-row {
  margin-top: 8px;
}

.select-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-size: 13.33px;
  min-height: 32px;
  padding: 6px 8px;
}

textarea {
  min-height: 160px;
  resize: vertical;
  line-height: 1.45;
}

input:disabled {
  background: #f3f6f8;
  color: #697586;
  cursor: not-allowed;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.metric {
  display: grid;
  gap: 8px;
  min-height: 128px;
  padding: 14px;
}

.metric span,
.panel-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  text-transform: uppercase;
}

.metric strong {
  font-size: 28px;
  letter-spacing: 0;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.cashflow-grid {
  display: grid;
  grid-template-columns: minmax(420px, 1.2fr) minmax(360px, 0.8fr);
  gap: 16px;
  margin-bottom: 16px;
}

.wide {
  grid-column: 1 / -1;
}

.panel {
  min-width: 0;
  padding: 14px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.panel-head.subhead {
  margin-top: 16px;
  margin-bottom: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.panel-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.panel-controls select {
  width: auto;
  max-width: 260px;
  min-height: 34px;
  padding: 6px 8px;
}

.panel-head h3 {
  margin: 0;
  font-size: 16px;
}

.exchange-data-panel {
  display: grid;
  gap: 10px;
}

.exchange-data-panel > * {
  min-width: 0;
}

.exchange-data-panel .panel-head {
  margin-bottom: 2px;
}

.exchange-data-panel .panel-head p {
  margin: 3px 0 0;
  font-size: 12px;
}

.exchange-pull-bar {
  display: grid;
  grid-template-columns: minmax(180px, 240px) auto;
  align-items: end;
  gap: 8px;
}

.exchange-pull-bar label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.exchange-currency-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 6px;
}

.exchange-currency {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  align-items: center;
  column-gap: 8px;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 8px;
  background: #fff;
  cursor: pointer;
}

.exchange-currency > input {
  width: 16px;
  min-height: 16px;
  margin: 0;
}

.exchange-currency > span {
  display: grid;
  min-width: 0;
}

.exchange-currency strong {
  font-size: 13px;
}

.exchange-currency small {
  overflow: hidden;
  font-size: 11.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.exchange-currency > small {
  grid-column: 2;
}

.exchange-currency.disabled {
  background: #f3f6f8;
  cursor: default;
}

.exchange-coverage-table {
  min-width: 520px;
}

.split {
  display: grid;
  grid-template-columns: minmax(300px, 0.9fr) minmax(420px, 1.3fr);
  gap: 16px;
  margin-bottom: 16px;
}

.form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.form .full,
.form button {
  grid-column: 1 / -1;
}

.check {
  grid-template-columns: auto minmax(0, 1fr) !important;
  align-items: center;
}

.check input {
  width: 18px;
  min-height: 18px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.35;
  padding: 6px 6px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.25;
  text-transform: uppercase;
}

td strong {
  font-size: 13px;
}

td small {
  font-size: 11.5px;
  line-height: 1.35;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
  padding: 2px 8px;
  white-space: nowrap;
}

.pill.warn {
  background: #fff4df;
  color: #84520f;
}

.pill.bad {
  background: #fee4e2;
  color: var(--danger);
}

.pull-artifacts {
  margin-top: 12px;
}

.run-log {
  display: grid;
  gap: 4px;
  margin-top: 10px;
}

.pill-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.bars {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(120px, 170px) minmax(120px, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.bar-label {
  min-width: 0;
  font-weight: 750;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: #e8edf0;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.bar-row:nth-child(2n) .bar-fill {
  background: var(--blue);
}

.bar-row:nth-child(3n) .bar-fill {
  background: var(--gold);
}

.bar-value {
  color: var(--muted);
  font-weight: 750;
  white-space: nowrap;
}

.cashflow-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.cashflow-metrics article {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfd;
  min-width: 0;
  padding: 10px;
  cursor: pointer;
}

.cashflow-metrics article:hover {
  border-color: rgba(15, 118, 110, 0.45);
  background: #f2fbf9;
}

.cashflow-metrics span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.cashflow-metrics strong {
  overflow-wrap: anywhere;
}

.cashflow-chart,
.stack-chart {
  display: grid;
  grid-template-columns: repeat(6, minmax(52px, 1fr));
  align-items: end;
  gap: 12px;
  min-height: 250px;
}

.cashflow-month,
.stack-month {
  display: grid;
  align-items: end;
  gap: 6px;
  min-width: 0;
  text-align: center;
}

.cashflow-bars {
  display: grid;
  grid-template-columns: repeat(2, minmax(10px, 1fr));
  align-items: end;
  gap: 4px;
  height: 145px;
  padding: 8px;
  border-radius: var(--radius);
  background: #eef2f5;
}

.cashflow-bars span {
  display: block;
  min-height: 3px;
  border-radius: 4px 4px 0 0;
  cursor: pointer;
}

.income-bar {
  background: #15803d;
}

.expense-bar {
  background: var(--danger);
}

.cashflow-month strong,
.stack-month strong {
  font-size: 12px;
}

.cashflow-month small,
.cashflow-month em {
  min-height: 18px;
  overflow-wrap: anywhere;
}

.cashflow-month em {
  color: var(--ink);
  font-size: 12px;
  font-style: normal;
  font-weight: 850;
}

.stack-chart {
  min-height: 190px;
}

.pnl-panel {
  display: grid;
  gap: 10px;
}

.pnl-chart {
  min-height: 520px;
  overflow-x: auto;
  border: 1px solid var(--line);
  background: #f8fafc;
}

.pnl-chart svg {
  display: block;
  width: 100%;
  min-width: 920px;
  height: auto;
}

.pnl-axis {
  stroke: #334155;
  stroke-width: 1.2;
}

.pnl-axis-label,
.pnl-chart text {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.pnl-net-label {
  fill: var(--ink);
  font-size: 10px;
  font-weight: 800;
}

.pnl-segment {
  cursor: pointer;
  shape-rendering: crispEdges;
}

.pnl-segment:hover {
  filter: brightness(0.92);
  stroke: #111827;
  stroke-width: 1;
}

.pnl-net-line {
  fill: none;
  stroke: #111827;
  stroke-width: 2.5;
}

.pnl-net-point {
  fill: #111827;
  stroke: #ffffff;
  stroke-width: 2;
}

.stack-bar {
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-start;
  height: 150px;
  overflow: hidden;
  border-radius: var(--radius);
  background: #eef2f5;
}

.stack-bar span {
  display: block;
  min-height: 3px;
  cursor: pointer;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 14px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}

.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.inline-select {
  min-width: 150px;
  min-height: 34px;
  padding: 6px 8px;
}

.attention-list,
.questions,
.source-steps,
.pull-steps {
  display: grid;
  gap: 10px;
}

.attention-item,
.question,
.source-steps article,
.pull-step,
.pull-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 12px;
}

.attention-item strong,
.question strong,
.source-steps strong,
.pull-state strong {
  display: block;
  margin-bottom: 4px;
}

.attention-item p,
.question p,
.source-steps p,
.pull-state p,
.pull-step p,
.muted {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.question textarea {
  margin-top: 10px;
  min-height: 70px;
}

.pull-card {
  display: grid;
  gap: 14px;
}

.dbs-scraper-panel {
  display: grid;
  gap: 16px;
  min-width: 0;
  max-width: 100%;
}

.dbs-scraper-panel > * {
  min-width: 0;
}

.source-credentials {
  display: grid;
  grid-template-columns: minmax(210px, 1fr) minmax(170px, 0.8fr) minmax(140px, 0.55fr) auto;
  align-items: end;
  gap: 10px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}

.source-credentials[hidden] {
  display: none;
}

.captcha-prompt {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(140px, 220px) minmax(180px, 1fr);
}

.captcha-prompt img {
  background: #fff;
  border: 1px solid var(--line);
  max-height: 72px;
  max-width: 220px;
  object-fit: contain;
  padding: 6px;
}

.remote-browser-panel {
  display: grid;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  border-top: 1px solid var(--line);
  padding: 12px 0;
}

.remote-browser-panel[hidden] {
  display: none;
}

.remote-browser-head {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.remote-browser-viewport {
  aspect-ratio: 16 / 9;
  background: #edf0f3;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-width: 960px;
  overflow: hidden;
  position: relative;
  width: 100%;
}

.remote-browser-viewport img {
  cursor: crosshair;
  display: block;
  height: 100%;
  object-fit: contain;
  transition: opacity 120ms ease;
  user-select: none;
  width: 100%;
}

.remote-browser-viewport img.is-pending {
  cursor: progress;
  opacity: 0.68;
}

@media (max-width: 680px) {
  .captcha-prompt {
    grid-template-columns: 1fr;
  }

  .remote-browser-head {
    align-items: stretch;
    flex-direction: column;
  }
}

.source-credentials label,
.credential-status {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

.credential-status strong {
  color: var(--ink);
  font-size: 14px;
}

.credential-status span {
  color: var(--accent-strong);
  font-weight: 750;
}

.statement-files {
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}

.statement-files summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  font-weight: 800;
  list-style: none;
  padding: 12px 14px;
}

.statement-files summary::-webkit-details-marker {
  display: none;
}

.statement-files summary::before {
  content: "▾";
  color: var(--muted);
  font-size: 12px;
}

.statement-files:not([open]) summary::before {
  content: "▸";
}

.statement-files summary span {
  margin-right: auto;
}

.statement-files .table-wrap {
  border-top: 1px solid var(--line);
}

.statement-files table {
  min-width: 820px;
}

.rules-table {
  min-width: 820px;
}

.rules-table input:not([type="checkbox"]) {
  min-width: 140px;
}

.rules-table .select-col {
  width: 54px;
  min-width: 54px;
  max-width: 54px;
  padding-left: 8px;
  padding-right: 8px;
  text-align: center;
}

.rules-table .compact-check {
  width: 14px;
  min-width: 14px;
  min-height: 14px;
  padding: 0;
  margin: 0;
  vertical-align: middle;
}

.rule-builder-form {
  grid-template-columns: minmax(160px, 0.7fr) minmax(220px, 1fr) repeat(3, minmax(170px, 1fr));
}

.rules-source-workspace {
  display: grid;
  gap: 0;
}

.rules-source-panel {
  display: grid;
  gap: 10px;
  padding-bottom: 14px;
}

.rules-subsection {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.rules-source-panel .select-label {
  max-width: 360px;
}

.rules-source-panel .panel-head span {
  text-transform: none;
}

.check-set {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0;
  min-height: 32px;
  padding: 6px 8px;
}

.check-set legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 0 4px;
}

.check-set label {
  display: inline-flex;
  align-items: center;
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
  gap: 5px;
}

.check-set input {
  width: 14px;
  min-height: 14px;
}

.rule-preview {
  margin-top: 12px;
}

.scraper-footnote {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.pull-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.pull-step {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.pull-step span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.pull-step.complete {
  border-color: rgba(15, 118, 110, 0.35);
  background: #edf8f6;
}

.pull-step.complete span {
  color: var(--accent);
}

.negative {
  color: var(--danger);
}

@media (max-width: 1100px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 14px;
  }

  .brand {
    margin-bottom: 12px;
  }

  .nav {
    grid-template-columns: repeat(8, minmax(0, 1fr));
    overflow: auto;
  }

  .nav-item {
    text-align: center;
    justify-content: center;
    white-space: nowrap;
  }

  .metrics,
  .cashflow-grid,
  .dashboard-grid,
  .split {
    grid-template-columns: 1fr 1fr;
  }

  .exchange-currency-grid {
    grid-template-columns: repeat(2, minmax(170px, 1fr));
  }
}

@media (max-width: 760px) {
  .main {
    padding: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .metrics,
  .cashflow-grid,
  .dashboard-grid,
  .split,
  .form {
    grid-template-columns: 1fr;
  }

  .source-credentials {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .exchange-pull-bar,
  .exchange-currency-grid {
    grid-template-columns: 1fr;
  }

  .cashflow-metrics,
  .cashflow-chart,
  .stack-chart {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .nav {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 3px;
  }

  .nav-item {
    flex: 0 0 auto;
  }

  .split-line {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .bar-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}
