/* Overview dashboard */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.overview {
  box-sizing: border-box;
  width: 100%;
  max-width: 70rem;
  margin-inline: auto;
}

/* Three columns so the month strip sits in the true horizontal center (equal 1fr sides). */
.overview-page__header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.overview-page__header .overview__title {
  grid-column: 1;
  justify-self: start;
  margin: 0;
}

.overview-page__header-mid {
  grid-column: 2;
  justify-self: center;
  display: flex;
  justify-content: center;
  min-width: 0;
}

@media (max-width: 52rem) {
  .overview-page__header {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .overview-page__header .overview__title {
    grid-column: 1;
    justify-self: center;
    text-align: center;
  }

  .overview-page__header-mid {
    grid-column: 1;
    width: 100%;
    max-width: min(100%, 28rem);
  }
}

.overview__title {
  margin: 0;
  font-size: clamp(1.75rem, 4vw, 2rem);
  font-weight: 700;
  color: var(--color-heading);
  letter-spacing: -0.02em;
}

/* Summary strip */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.summary-card {
  padding: 1.25rem 1.5rem;
  border-radius: 0.75rem;
  box-shadow: none;
}

.summary-card--balance {
  background-color: var(--color-primary-dark);
  color: #fff;
}

.summary-card--income,
.summary-card--expenses {
  background-color: var(--color-card);
  color: var(--color-heading);
}

.summary-card__label {
  margin: 0 0 0.35rem;
  font-size: 0.875rem;
  font-weight: 400;
  opacity: 0.85;
}

.summary-card__scope {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.35;
  color: var(--color-text-muted);
}

.summary-card--balance .summary-card__label {
  margin-bottom: 0.75rem;
  opacity: 0.7;
}

.summary-card--income .summary-card__label,
.summary-card--expenses .summary-card__label {
  margin-bottom: 0.25rem;
}

[data-theme="dark"] .summary-card--balance {
  background-color: #e5e5e5;
  color: #201f24;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.06);
}

[data-theme="dark"] .summary-card--balance .summary-card__label {
  color: #201f24;
  opacity: 0.55;
}

[data-theme="dark"] .summary-card--balance .summary-card__value {
  color: #201f24;
}

.summary-card__value {
  margin: 0;
  font-size: clamp(1.75rem, 4vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Shared card chrome */
.overview-card {
  padding: 1.5rem;
  background-color: var(--color-card);
  border-radius: 0.75rem;
}

.overview-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.overview-card__title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--color-heading);
}

.overview-card__link {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem;
  margin: -0.25rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.overview-card__link:hover {
  color: var(--color-link-hover-text);
}

[data-theme="dark"] .overview-card__link-icon {
  filter: brightness(0) saturate(0) invert(0.72);
}

.overview-card__link:focus-visible {
  outline: 2px solid var(--color-accent-green);
  outline-offset: 2px;
}

.overview-card__link-icon {
  width: 0.75rem;
  height: 0.75rem;
  flex-shrink: 0;
}

/* Two-column dashboard */
.overview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

.overview-grid__col {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Pots */
.pots-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem;
  align-items: stretch;
}

@media (max-width: 54rem) {
  .pots-layout {
    grid-template-columns: 1fr;
  }
}

.pots-total {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background-color: var(--color-subtle-fill);
  border-radius: 0.75rem;
}

.pots-total__label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--color-text-muted);
}

.pots-total__icon {
  width: 1.5rem;
  height: 1.5rem;
}

.pots-total__value {
  margin: 0;
  font-size: clamp(1.75rem, 3vw, 2rem);
  font-weight: 700;
  color: var(--color-heading);
}

.pots-mini-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.pots-mini {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0;
}

.pots-mini__accent {
  width: 0.25rem;
  align-self: stretch;
  min-height: 2.75rem;
  border-radius: 0.125rem;
  flex-shrink: 0;
}

.pots-mini__meta {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  min-width: 0;
}

.pots-mini__name {
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pots-mini__amount {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-heading);
}

/* Transactions list */
.tx-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.tx-row__avatar-cell {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  flex-shrink: 0;
}

.tx-row__avatar-cell > * {
  grid-area: 1 / 1;
}

.overview-error {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  background-color: var(--color-error-bg);
  color: var(--color-heading);
  font-size: 0.875rem;
}

.tx-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 1rem;
  align-items: center;
  padding: 1rem 0;
  border-bottom: 1px solid var(--color-divider);
  color: inherit;
  border-radius: 0.375rem;
  margin-inline: -0.375rem;
  padding-inline: 0.375rem;
}

.tx-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.tx-row:first-child {
  padding-top: 0;
}

.tx-row__avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.tx-row__avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background-color: var(--color-tx-avatar-fallback-bg);
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-heading);
}

/* Class `display` beats the `hidden` attribute otherwise — keep fallback truly hidden until shown */
.tx-row__avatar-fallback[hidden] {
  display: none !important;
}

.tx-row__name {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-heading);
  min-width: 0;
}

.tx-row__amount {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 700;
  white-space: nowrap;
}

.tx-row__amount--credit {
  color: var(--color-accent-green);
}

.tx-row__amount--debit {
  color: var(--color-heading);
}

.tx-row__date {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* Wide: amount + date participate directly in the 4-column row */
.tx-row__meta {
  display: contents;
}

.overview-card--transactions {
  container-type: inline-size;
  container-name: tx-card;
}

/* Compact rows when the *card* is narrow (e.g. two-column overview), not only tiny viewports */
@container tx-card (max-width: 36rem) {
  .tx-row {
    grid-template-columns: 2.5rem 1fr;
    grid-template-rows: auto auto;
    align-items: start;
    column-gap: 1rem;
    row-gap: 0.375rem;
  }

  .tx-row__avatar-cell {
    grid-row: 1 / span 2;
    align-self: center;
  }

  .tx-row__name {
    grid-column: 2;
    grid-row: 1;
  }

  .tx-row__meta {
    display: flex;
    grid-column: 2;
    grid-row: 2;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    min-width: 0;
  }

  .tx-row__amount {
    justify-self: unset;
  }

  .tx-row__date {
    justify-self: unset;
  }
}

/* Budgets donut */
.budgets-body {
  display: grid;
  /* Donut column needs a definite min track — minmax(0, auto) can collapse to 0 when width is % of the column */
  grid-template-columns: minmax(9rem, 11rem) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: center;
}

@media (max-width: 36rem) {
  .budgets-body {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .budgets-legend {
    width: 100%;
  }
}

.budgets-donut-wrap {
  position: relative;
  justify-self: center;
  box-sizing: border-box;
  width: 100%;
  max-width: 11rem;
  aspect-ratio: 1;
  /* Keep center labels from painting over the legend in the next grid column */
  overflow: hidden;
  border-radius: 50%;
}

.budgets-donut {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  /* Gradient filled via JS; mask creates donut hole */
  mask: radial-gradient(farthest-side, transparent calc(65% - 1px), #000 65%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(65% - 1px), #000 65%);
  mask-repeat: no-repeat;
  -webkit-mask-repeat: no-repeat;
  mask-position: center;
  -webkit-mask-position: center;
}

.budgets-donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 12%;
  box-sizing: border-box;
  text-align: center;
  pointer-events: none;
}

.budgets-donut-center__spent {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--color-heading);
}

.budgets-donut-center__limit {
  margin: 0.125rem 0 0;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--color-text-muted);
}

.budgets-legend {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.budgets-legend__row {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.budgets-legend__swatch {
  width: 0.25rem;
  align-self: stretch;
  min-height: 2.75rem;
  border-radius: 0.125rem;
  flex-shrink: 0;
}

.budgets-legend__label {
  flex: 1;
  min-width: 0;
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--color-text-muted);
}

.budgets-legend__value {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-heading);
  white-space: nowrap;
}

/* Recurring summary bars */
.recurring-bars {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.recurring-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background-color: var(--color-subtle-fill);
  border-radius: 0.5rem;
  border-left: 0.25rem solid transparent;
}

.recurring-bar__body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.recurring-bar__label {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--color-text-muted);
}

.recurring-bar__value {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-heading);
}

.recurring-bar--paid {
  border-left-color: var(--color-accent-green);
}

.recurring-bar--upcoming {
  border-left-color: #f2cdac;
}

.recurring-bar--due {
  border-left-color: #82c9d7;
}

/* Credit cards summary (matches recurring row layout) */
.overview-cc-bars {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.overview-cc-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background-color: var(--color-subtle-fill);
  border-radius: 0.5rem;
  border-left: 0.25rem solid transparent;
}

.overview-cc-row__body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-width: 0;
}

.overview-cc-row__label {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--color-text-muted);
}

.overview-cc-row__value {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-heading);
  white-space: nowrap;
}

.overview-cc-row--accent-0 {
  border-left-color: #277c78;
}

.overview-cc-row--accent-1 {
  border-left-color: #82c9d7;
}

.overview-cc-row--accent-2 {
  border-left-color: #f2cdac;
}

.overview-cc-row--accent-3 {
  border-left-color: #626070;
}

.overview-cc-row--accent-4 {
  border-left-color: #826cb0;
}

.overview-cc-empty {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--color-text-muted);
}

@media (max-width: 56rem) {
  .summary-cards {
    grid-template-columns: 1fr;
  }

  .summary-card {
    text-align: center;
  }

  .pots-total {
    align-items: center;
    text-align: center;
  }

  .pots-total__label {
    justify-content: center;
  }
}

/* Stack overview columns earlier — otherwise each ~½ shell width is too narrow beside the sidebar */
@media (max-width: 68rem) {
  .overview-grid {
    grid-template-columns: 1fr;
  }
}
