.stats {
  --bar: #3987e5;
  --income: #199e70;
  --expense: #d95926;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #2f9e2f;
  --series-7: #9085e9;
  --series-8: #e66767;
  --series-9: #0e9aa7;
  --series-other: #6b6b6b;
  --series-uncategorized: #d4d4d4;
}

.stats h1 {
  margin-bottom: 0;
}

.period-header {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.stats-period {
  margin: 0;
}

.period-step {
  padding: 0 0.5rem;
  border: 1px solid var(--hairline);
  color: inherit;
  text-decoration: none;
  font-size: 1.1rem;
  line-height: 1.6;
}

.period-step:hover {
  background: var(--track);
}

.period-step-disabled {
  color: var(--hairline);
}

.dropdown {
  position: relative;
}

.dropdown > summary,
.other-period > summary {
  cursor: pointer;
  font-size: 0.9rem;
}

.view-options {
  margin-left: auto;
}

.view-options > summary {
  padding: 0.2rem 0.7rem;
  border: 1px solid var(--hairline);
}

.dropdown-body {
  position: absolute;
  right: 0;
  z-index: 10;
  display: grid;
  gap: 0.75rem;
  width: max-content;
  max-width: calc(100vw - 2rem);
  margin-top: 0.25rem;
  padding: 0.75rem;
  border: 1px solid var(--hairline);
  background: var(--surface);
}

.other-period {
  margin: 0.5rem 0 1.5rem;
}

.other-period > summary {
  color: var(--muted);
}

.other-period-body {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  align-items: center;
  margin-top: 0.5rem;
}

.month-tabs {
  display: flex;
  gap: 0.1rem;
  margin-top: 1rem;
  overflow-x: auto;
  scrollbar-width: thin;
}

.month-tab {
  flex: none;
  padding: 0.3rem 0.45rem;
  color: inherit;
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
}

.month-tab:hover {
  background: var(--track);
}

.month-tab-active {
  background: var(--accent);
  color: #fff;
}

.month-tab-active:hover {
  background: var(--accent-hover);
}

.quick-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.currency-filter,
.scope-filter {
  align-items: center;
}

.rate-note {
  font-size: 0.85rem;
}

.chip {
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--hairline);
  color: inherit;
  text-decoration: none;
  font-size: 0.9rem;
}

.chip:hover {
  background: var(--track);
}

.chip-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.chip-active:hover {
  background: var(--accent-hover);
}

.timeline-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.9rem;
}

.timeline-filter .field {
  white-space: nowrap;
}

.timeline-filter input[type="date"] {
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: inherit;
  font: inherit;
}

.timeline-filter .button {
  padding: 0.35rem 0.9rem;
}

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.stat-tile {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1rem;
  border: 1px solid var(--hairline);
  background: var(--surface);
}

.stat-tile .muted {
  font-size: 0.85rem;
}

.stat-tile strong {
  font-size: 1.3rem;
  white-space: nowrap;
}

.trend {
  font-size: 0.8rem;
}

.trend-better,
.amount-positive {
  color: var(--positive);
}

.trend-worse,
.amount-negative {
  color: var(--negative);
}

.net-worth-now {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
}

.net-worth-now .stat-tile {
  flex: 1 1 14rem;
}

.section-heading {
  position: relative;
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
}

.info > summary {
  list-style: none;
  color: var(--muted);
  cursor: pointer;
}

.info > summary::-webkit-details-marker {
  display: none;
}

.info[open] > summary {
  color: var(--text);
}

.info-body {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: 10;
  padding: 0.75rem 1rem;
  border: 1px solid var(--hairline);
  background: var(--surface);
  font-size: 0.85rem;
}

.chart-scroll {
  overflow-x: auto;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--hairline);
}

.tab {
  padding: 0.5rem 1rem;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.net-worth-chart {
  display: block;
  width: 100%;
  min-width: 30rem;
  overflow: visible;
}

.net-worth-grid {
  stroke: var(--hairline);
  stroke-width: 1;
}

.net-worth-label {
  fill: var(--muted);
  font-size: 14px;
}

.net-worth-line {
  fill: none;
  stroke: var(--bar);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.net-worth-point {
  fill: var(--bar);
  stroke: var(--background);
  stroke-width: 2;
}

.net-worth-changes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: 0.75rem;
}

.net-worth-change {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1rem;
  border: 1px solid var(--hairline);
  background: var(--surface);
}

.net-worth-change strong {
  font-variant-numeric: tabular-nums;
}

.stats-section {
  margin-top: 1.5rem;
}

.stats-section h2 {
  margin-bottom: 0.5rem;
}

.stats-section h2 .muted {
  font-weight: normal;
}

.bars {
  margin: 0;
  padding: 0;
  list-style: none;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(8rem, 12rem) 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.2rem 0;
  font-size: 0.9rem;
}

.bar-row:hover {
  background: var(--track);
}

.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 0.75rem;
}

.bar {
  display: block;
  height: 100%;
  min-width: 2px;
  background: var(--bar);
}

.bars-income .bar {
  background: var(--income);
}

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

.bar-row-uncategorized .bar {
  background: var(--series-uncategorized);
}

.bar-value,
.legend-value {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.pies {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 0 2rem;
}

.pie {
  display: block;
  width: 100%;
  max-width: 14rem;
  margin: 0.5rem auto 1rem;
}

.pie-slice {
  stroke: var(--surface);
  stroke-width: 2;
}

.pie-slice:hover {
  opacity: 0.8;
}

.pie-total {
  fill: currentColor;
  font-size: 15px;
  font-weight: 600;
}

.legend {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
}

.legend li {
  display: grid;
  grid-template-columns: 0.75rem 1fr auto;
  gap: 0.5rem;
  align-items: center;
}

.swatch {
  width: 0.75rem;
  height: 0.75rem;
}

.series-1 { fill: var(--series-1); background: var(--series-1); }
.series-2 { fill: var(--series-2); background: var(--series-2); }
.series-3 { fill: var(--series-3); background: var(--series-3); }
.series-4 { fill: var(--series-4); background: var(--series-4); }
.series-5 { fill: var(--series-5); background: var(--series-5); }
.series-6 { fill: var(--series-6); background: var(--series-6); }
.series-7 { fill: var(--series-7); background: var(--series-7); }
.series-8 { fill: var(--series-8); background: var(--series-8); }
.series-9 { fill: var(--series-9); background: var(--series-9); }
.series-other { fill: var(--series-other); background: var(--series-other); }
.series-uncategorized { fill: var(--series-uncategorized); background: var(--series-uncategorized); }

@media (max-width: 32rem) {
  .bar-row {
    grid-template-columns: 1fr auto;
  }

  .bar-track {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

.ledger-scroll {
  overflow-x: auto;
}

.ledger {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.ledger th,
.ledger td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--hairline);
  text-align: left;
  white-space: nowrap;
}

.ledger thead th {
  font-weight: 600;
}

.ledger tbody th {
  font-weight: normal;
}

.ledger tfoot th,
.ledger tfoot td {
  border-bottom: 0;
  font-weight: 600;
}

.ledger tbody th {
  min-width: 9rem;
  white-space: normal;
}

.ledger tbody th .muted {
  display: block;
  font-size: 0.85rem;
}

.loans-summary {
  margin: 0 0 0.5rem;
}

.ledger .number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.ledger-note {
  font-size: 0.85rem;
}

/* Budget */
.budget-rows {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
}

.budget-row {
  display: grid;
  grid-template-columns: minmax(8rem, 12rem) 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.3rem 0.25rem;
}

.budget-row .bar-track {
  position: relative;
}

.budget-allotment,
.budget-row .bar {
  position: absolute;
  inset: 0 auto 0 0;
}

.budget-allotment {
  background: var(--track);
}

.budget-row .bar {
  height: auto;
  background: var(--series-3);
}

.budget-limit {
  position: absolute;
  top: -0.2rem;
  bottom: -0.2rem;
  width: 2px;
  margin-left: -1px;
  background: var(--text);
}

.budget-row-over .bar {
  background: var(--series-8);
}

.budget-row-total {
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.budget-row-total .bar-track {
  height: 1.25rem;
}

.budget-form-details summary {
  cursor: pointer;
  color: var(--link);
}

.budget-form {
  margin-top: 0.75rem;
}

.budget-dates {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.budget-lines {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 0.4rem 1rem;
}

.budget-line {
  display: grid;
  grid-template-columns: 1fr 7rem;
  gap: 0.5rem;
  align-items: center;
}

.budget-line input {
  width: 100%;
}

.budget-actions {
  font-size: 0.9rem;
}

.budget-actions .button-to {
  display: inline;
}

@media (max-width: 40rem) {
  .budget-row {
    grid-template-columns: 1fr auto;
  }

  .budget-row .bar-track {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

.bar-details > summary {
  list-style: none;
  cursor: pointer;
}

.bar-details > summary::-webkit-details-marker {
  display: none;
}

.bar-details .bar-label::before {
  content: "▸";
  display: inline-block;
  width: 1em;
  color: var(--series-other);
  transition: transform 0.15s;
}

.bar-details[open] .bar-label::before {
  transform: rotate(90deg);
}

.bar-details .ledger-scroll {
  margin: 0.25rem 0 1rem;
}

.ledger.transactions {
  font-size: 0.8rem;
}

.ledger.transactions .description {
  min-width: 12rem;
  white-space: normal;
}
