/* 预算页专用布局。所有覆盖均限制在 .budget-page，避免影响记账页共用预算卡。 */
.budget-page {
  min-width: 0;
}

.budget-page .budget-page-header {
  gap: 20px;
  margin-bottom: 16px;
}

.budget-page .budget-page-header > div:first-child,
.budget-page .budget-page-month {
  min-width: 0;
}

.budget-page .budget-page-month {
  display: flex;
  align-items: center;
  gap: 8px;
}

.budget-page .budget-page-tabs {
  min-width: 0;
}

.budget-page .budget-page-tabs .seg-tabs {
  margin-bottom: 20px;
}

.budget-page .budget-overview-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 20px;
  margin-bottom: 20px;
}

.budget-page .budget-overview-panel--over {
  border: 1.5px solid var(--danger);
}

.budget-page .budget-overview-metrics {
  min-width: 0;
}

.budget-page .budget-overview-label {
  color: var(--text-secondary);
  font-size: 13px;
}

.budget-page .budget-overview-amount {
  margin-top: 2px;
  color: var(--text);
  font-size: clamp(22px, 3vw, 28px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  white-space: nowrap;
}

.budget-page .budget-overview-quota {
  margin-top: 5px;
  color: var(--text-secondary);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.budget-page .budget-overview-quota strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.budget-page .budget-overview-balance {
  margin-top: 5px;
  font-size: 13px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.budget-page .budget-overview-balance--unset {
  color: var(--text-secondary);
  font-weight: 500;
}

.budget-page .budget-overview-balance--ok {
  color: var(--success);
}

.budget-page .budget-overview-balance--over {
  color: var(--danger);
  font-weight: 800;
}

.budget-page .budget-overview-actions {
  display: flex;
  align-items: center;
}

.budget-page .budget-overview-actions .btn {
  white-space: nowrap;
}

.budget-page .budget-category-panel,
.budget-page .budget-consumables-panel {
  min-width: 0;
}

.budget-page .budget-ring-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 14px;
}

.budget-page .bg-ring-card {
  min-width: 0;
  min-height: 132px;
  padding: 16px;
  align-items: flex-start;
  gap: 12px;
}

.budget-page .bg-ring-card > .ring {
  width: 64px;
  height: 64px;
  flex: 0 0 64px;
}

.budget-page .bg-ring-card > .ring::before {
  inset: 7px;
}

.budget-page .bg-ring-card > .ring .ring-inner {
  max-width: 50px;
  line-height: 1.05;
}

.budget-page .bg-ring-card > .ring .ring-num {
  font-size: 14px;
  overflow-wrap: anywhere;
}

.budget-page .bg-ring-card > .ring .ring-cap {
  font-size: 9px;
}

.budget-page .bg-ring-meta {
  display: flex;
  min-width: 0;
  min-height: 98px;
  flex: 1;
  flex-direction: column;
  align-self: stretch;
}

.budget-page .bg-ring-name {
  min-width: 0;
  align-items: flex-start;
  overflow-wrap: anywhere;
  white-space: normal;
}

.budget-page .bg-line-spent,
.budget-page .bg-line-budget {
  max-width: 100%;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.budget-page .bg-set-btn {
  min-height: 30px;
  margin-top: auto;
  padding: 7px 0 0;
  text-align: left;
}

.budget-page .bg-set-btn:focus-visible,
.budget-page .cs-product-toggle:focus-visible {
  border-radius: 4px;
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.budget-page .budget-consumables-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.budget-page .budget-consumables-summary {
  min-width: 0;
}

.budget-page .budget-consumables-count {
  color: var(--text-secondary);
  font-size: 13px;
}

.budget-page .budget-consumables-alert {
  margin-top: 2px;
  font-size: 20px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.budget-page .budget-consumables-alert span {
  color: var(--danger);
}

.budget-page .budget-consumables-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.budget-page .budget-consumables-actions .btn {
  margin: 0;
}

.budget-page .budget-consumables-table-wrap {
  min-width: 0;
  overflow-x: auto;
}

.budget-page .cs-product-table {
  min-width: 980px;
  font-size: 13px;
}

.budget-page .cs-product-toggle {
  display: inline-flex;
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.budget-page .cs-product-toggle:hover {
  border-color: var(--border);
  background: var(--primary-bg);
  color: var(--primary);
}

.budget-page .cs-product-chevron {
  width: auto;
  line-height: 1;
}

.budget-page .cs-product-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.budget-page .cs-cell-value {
  min-width: 0;
}

@media (max-width: 768px) {
  .budget-page .budget-page-header {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
  }

  .budget-page .budget-page-header .page-subtitle {
    overflow-wrap: anywhere;
  }

  .budget-page .budget-page-tabs .seg-tabs {
    display: flex;
    width: 100%;
    margin-bottom: 16px;
  }

  .budget-page .budget-page-tabs .seg-tab {
    min-width: 0;
    flex: 1;
    padding-inline: 10px;
  }

  .budget-page .card {
    padding: 16px;
  }

  .budget-page .budget-overview-panel {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    gap: 14px;
  }

  .budget-page .budget-overview-panel > .ring {
    width: 76px;
    height: 76px;
  }

  .budget-page .budget-overview-panel > .ring::before {
    inset: 9px;
  }

  .budget-page .budget-overview-actions {
    grid-column: 1 / -1;
  }

  .budget-page .budget-overview-actions,
  .budget-page .budget-overview-actions .btn {
    width: 100%;
  }

  .budget-page .budget-ring-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .budget-page .budget-consumables-toolbar {
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
  }

  .budget-page .budget-consumables-actions {
    justify-content: flex-start;
  }

  .budget-page .budget-consumables-actions .btn {
    min-width: min(100%, 150px);
    flex: 1 1 150px;
    white-space: normal;
  }

  .budget-page .budget-consumables-panel .card-header span {
    display: block;
    margin-top: 4px;
    line-height: 1.5;
  }

  .budget-page .budget-consumables-table-wrap {
    overflow: visible;
  }

  .budget-page .cs-product-table {
    min-width: 0;
  }

  .budget-page .cs-product-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    clip-path: inset(50%);
    overflow: hidden;
    white-space: nowrap;
  }

  .budget-page .cs-product-table,
  .budget-page .cs-product-table > tbody,
  .budget-page .cs-product-table > tbody > tr,
  .budget-page .cs-product-table > tbody > tr > td,
  .budget-page .cs-product-detail-table,
  .budget-page .cs-product-detail-table tbody,
  .budget-page .cs-product-detail-table tr,
  .budget-page .cs-product-detail-table td {
    display: block;
    width: 100%;
  }

  .budget-page .cs-product-table > tbody {
    display: grid;
    gap: 12px;
  }

  .budget-page .cs-product-table > tbody > .cs-product-row {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
  }

  .budget-page .cs-product-table > tbody > .cs-product-row > td,
  .budget-page .cs-product-detail-table td {
    display: grid;
    max-width: none;
    grid-template-columns: minmax(86px, 35%) minmax(0, 1fr);
    align-items: start;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    overflow: visible;
    text-align: right;
    text-overflow: clip;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .budget-page .cs-product-table .cs-cell-value {
    min-width: 0;
    grid-column: 2;
  }

  .budget-page .cs-product-table > tbody > .cs-product-row > .cs-product-primary-cell {
    display: block;
    padding-bottom: 10px;
    text-align: left;
  }

  .budget-page .cs-product-primary-cell::before {
    display: none;
  }

  .budget-page .cs-product-primary-cell .cs-cell-value {
    display: block;
  }

  .budget-page .cs-product-table > tbody > .cs-product-row > td:last-child,
  .budget-page .cs-product-detail-table td:last-child {
    border-bottom: 0;
  }

  .budget-page .cs-product-table td::before {
    content: attr(data-label);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    text-align: left;
  }

  .budget-page .cs-product-table td[colspan]::before {
    display: none;
  }

  .budget-page .cs-product-title {
    justify-content: flex-start;
    text-align: left;
  }

  .budget-page .cs-product-category {
    margin-right: 0;
    margin-left: 0;
    margin-left: 34px;
    text-align: left;
  }

  .budget-page .cs-product-actions .cs-cell-value {
    display: flex;
    max-width: 100%;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
  }

  .budget-page .cs-product-actions .btn {
    min-width: 42px;
    white-space: normal;
  }

  .budget-page .cs-product-actions .btn + .btn {
    margin-left: 0;
  }

  .budget-page .cs-product-detail-row > td {
    padding: 0;
    border-bottom: 0;
    background: transparent;
  }

  .budget-page .cs-product-detail-wrap {
    margin: -6px 8px 2px;
    padding: 10px;
    overflow: visible;
  }

  .budget-page .cs-product-detail-table tbody {
    display: grid;
    gap: 10px;
  }

  .budget-page .cs-product-detail-table tr {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
  }

  .budget-page .cs-product-empty-row > td {
    display: block;
    padding: 0;
  }
}

@media (max-width: 360px) {
  .budget-page .card {
    padding: 14px;
  }

  .budget-page .budget-overview-panel {
    gap: 10px;
  }

  .budget-page .budget-overview-panel > .ring {
    width: 68px;
    height: 68px;
  }

  .budget-page .budget-overview-amount {
    font-size: 20px;
  }

  .budget-page .cs-product-table > tbody > .cs-product-row > td,
  .budget-page .cs-product-detail-table td {
    grid-template-columns: minmax(78px, 34%) minmax(0, 1fr);
    gap: 8px;
  }
}
