/* ============================================================
   Budgeting Calculator — Styles
   ============================================================ */

/* ---- Two-column layout ---- */
.bg-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 960px) {
  .bg-columns { grid-template-columns: 1fr; }
}

/* ---- Sections ---- */
.bg-section {
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 1rem;
}

.bg-section__header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  font-weight: 600;
}

.bg-section__header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.bg-section__icon {
  font-size: 1.25rem;
}

.bg-section--income .bg-section__header {
  background: #e8f5e9;
  border-bottom: 2px solid #2d6a4f;
  color: #1b5e20;
}

.bg-section--reserves .bg-section__header {
  background: #e3f2fd;
  border-bottom: 2px solid #1565c0;
  color: #0d47a1;
}

.bg-section--expenses .bg-section__header {
  background: #fbe9e7;
  border-bottom: 2px solid #c62828;
  color: #b71c1c;
}

/* ---- Categories ---- */
.bg-category {
  padding: 0 1rem;
}

.bg-category__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid #e0e0e0;
  font-weight: 600;
  font-size: 0.875rem;
  color: #424242;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.bg-category__header--primary {
  color: #c62828;
  font-size: 0.9rem;
}

.bg-category__total {
  font-family: 'Courier New', monospace;
  font-weight: 700;
  color: #333;
}

.bg-category__items {
  padding: 0.25rem 0;
}

/* ---- Rows ---- */
.bg-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
}

.bg-row label {
  flex: 1;
  font-size: 0.85rem;
  color: #555;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bg-row__period {
  font-size: 0.75rem;
  color: #999;
  width: 2rem;
  text-align: left;
}

/* ---- Inputs ---- */
.bg-input {
  width: 120px;
  padding: 0.35rem 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  text-align: right;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
}

.bg-input:focus {
  border-color: #2d6a4f;
  outline: none;
  box-shadow: 0 0 0 2px rgba(45,106,79,0.15);
}

.bg-input--computed {
  background: #f5f5f5;
  color: #666;
}

/* ---- Dynamic Income Rows ---- */
.bg-income-row {
  padding: 0.2rem 0;
}

.bg-income-row__main {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.bg-income-row__name {
  flex: 1.5;
  min-width: 0;
  padding: 0.3rem 0.5rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.82rem;
  color: #333;
}

.bg-income-row__type {
  flex: 0.8;
  min-width: 0;
  padding: 0.3rem 0.5rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.82rem;
  color: #666;
}

.bg-income-row__amount {
  width: 100px;
  flex-shrink: 0;
}

.bg-income-row__name:focus,
.bg-income-row__type:focus {
  border-color: #2d6a4f;
  outline: none;
  box-shadow: 0 0 0 2px rgba(45,106,79,0.15);
}

/* ---- Liability Table ---- */
.bg-liabilities-table {
  margin: 0.5rem 0;
}

.bg-liab-header {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0;
  border-bottom: 2px solid #e0e0e0;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #777;
}

.bg-liab-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid #f0f0f0;
  transition: opacity 0.2s, background 0.2s;
}

.bg-liab-row:hover {
  background: #fafafa;
}

.bg-liab-row--omitted {
  opacity: 0.45;
  background: #f5f5f5;
}

.bg-liab-row--omitted:hover {
  opacity: 0.7;
}

.bg-liab-row--payoff {
  background: #fff8e1;
}

.bg-liab-row--payoff:hover {
  background: #fff3c4;
}

/* Liability column widths */
.bg-liab-col--name {
  flex: 2;
  min-width: 0;
  font-size: 0.82rem;
}

.bg-liab-row .bg-liab-col--name {
  padding: 0.3rem 0.4rem;
  border: 1px solid #ddd;
  border-radius: 3px;
}

.bg-liab-col--type {
  flex: 0.8;
  min-width: 0;
  font-size: 0.75rem;
  color: #777;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bg-liab-col--balance {
  width: 90px;
  flex-shrink: 0;
}

.bg-liab-col--payment {
  width: 80px;
  flex-shrink: 0;
}

.bg-liab-col--months {
  width: 45px;
  flex-shrink: 0;
  text-align: center;
}

.bg-liab-col--omit,
.bg-liab-col--payoff {
  width: 36px;
  flex-shrink: 0;
  text-align: center;
}

.bg-liab-col--remove {
  width: 24px;
  flex-shrink: 0;
  text-align: center;
}

.bg-liab-check {
  display: flex;
  justify-content: center;
  cursor: pointer;
}

.bg-liab-check input[type="checkbox"] {
  cursor: pointer;
  width: 16px;
  height: 16px;
  accent-color: #2d6a4f;
}

/* Liability table input sizing — do NOT set width:100% here,
   it overrides the column-specific widths and breaks the flex layout */
.bg-liab-row .bg-input {
  padding: 0.25rem 0.35rem;
  font-size: 0.8rem;
}

/* Liability summary */
.bg-liab-summary {
  padding: 0.5rem 0;
  border-top: 1px solid #e0e0e0;
  margin-top: 0.25rem;
}

.bg-liab-summary__row {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  padding: 0.15rem 0;
  color: #666;
}

.bg-liab-summary__row span:last-child {
  font-weight: 600;
  font-family: 'Courier New', monospace;
}

.bg-liab-summary__row--payoff {
  color: #e65100;
  font-weight: 600;
}

/* Add row button */
.bg-add-row-btn {
  display: inline-block;
  margin: 0.4rem 0;
  padding: 0.3rem 0.75rem;
  border: 1px dashed #bbb;
  border-radius: 4px;
  background: none;
  color: #666;
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.bg-add-row-btn:hover {
  border-color: #2d6a4f;
  color: #2d6a4f;
}

/* ---- Income Adjustments ---- */
.bg-category--adjustments .bg-row label {
  color: #333;
}

.bg-grand-total--net-income {
  background: #e8f5e9;
  color: #1b5e20;
  border-top: 2px solid #2d6a4f;
}

.bg-card__row--deduction {
  color: #c62828;
}

/* ---- DTI Gauge limit marker ---- */
.bg-gauge__limit {
  color: #c62828;
  font-weight: 600;
}

/* ---- Subtotals & Grand Totals ---- */
.bg-subtotal {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  border-top: 1px solid #e0e0e0;
  font-weight: 600;
  font-size: 0.9rem;
  color: #333;
}

.bg-grand-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  font-weight: 700;
  font-size: 1.05rem;
}

.bg-grand-total--income {
  background: #c8e6c9;
  color: #1b5e20;
  border-top: 2px solid #2d6a4f;
}

.bg-grand-total--expenses {
  background: #ffcdd2;
  color: #b71c1c;
  border-top: 2px solid #c62828;
}

/* ---- Reserves ---- */
.bg-reserves-months {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  color: #555;
  background: #e3f2fd;
  border-top: 1px solid #bbdefb;
}

.bg-reserves-months span:last-child {
  font-weight: 700;
  font-size: 1rem;
  color: #1565c0;
}

/* ---- Results Dashboard ---- */
.bg-results {
  margin-top: 0.5rem;
}

.bg-results__cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-top: 0.75rem;
}

@media (max-width: 1100px) {
  .bg-results__cards { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .bg-results__cards { grid-template-columns: 1fr; }
}

.bg-card {
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
  background: #fff;
}

.bg-card__label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #777;
  margin-bottom: 0.25rem;
}

.bg-card__value {
  font-size: 1.8rem;
  font-weight: 700;
  color: #2d6a4f;
  font-family: 'Courier New', monospace;
  line-height: 1.2;
}

.bg-card__detail {
  font-size: 0.75rem;
  color: #999;
  margin-bottom: 0.5rem;
}

.bg-card__breakdown {
  text-align: left;
  border-top: 1px solid #eee;
  padding-top: 0.5rem;
  margin-top: 0.25rem;
}

.bg-card__row {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  padding: 0.15rem 0;
  color: #555;
}

.bg-card__row span:last-child {
  font-family: 'Courier New', monospace;
  font-weight: 600;
}

.bg-card__row--highlight {
  color: #e65100;
  font-weight: 600;
  border-top: 1px dashed #e0e0e0;
  margin-top: 0.2rem;
  padding-top: 0.3rem;
}

.bg-card__status {
  font-size: 0.75rem;
  margin-top: 0.5rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-weight: 600;
}

.bg-card__status--good {
  background: #e8f5e9;
  color: #2e7d32;
}

.bg-card__status--warn {
  background: #fff3e0;
  color: #e65100;
}

.bg-card__status--over {
  background: #ffebee;
  color: #c62828;
}

/* ---- DTI Gauge ---- */
.bg-gauge {
  height: 8px;
  background: #e0e0e0;
  border-radius: 4px;
  overflow: hidden;
  margin: 0.4rem 0 0.2rem;
}

.bg-gauge__fill {
  height: 100%;
  border-radius: 4px;
  background: #2d6a4f;
  transition: width 0.3s ease, background-color 0.3s ease;
  min-width: 0;
}

.bg-gauge__fill--warn {
  background: #f57c00;
}

.bg-gauge__fill--over {
  background: #c62828;
}

.bg-gauge__labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: #999;
}

.bg-gauge__threshold {
  color: #f57c00;
  font-weight: 600;
}

/* ---- Remove button ---- */
.bg-row__remove {
  background: none;
  border: none;
  color: #c62828;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
  opacity: 0.6;
  flex-shrink: 0;
}

.bg-row__remove:hover {
  opacity: 1;
}

/* ---- Disclaimer ---- */
.bg-disclaimer {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: #f5f5f5;
  border-radius: 4px;
  font-size: 0.82rem;
  color: #666;
}

/* ---- Print ---- */
@media print {
  .bg-add-row-btn,
  .bg-row__remove,
  .action-bar,
  .bg-disclaimer { display: none; }

  /* Stack columns vertically to fit letter width */
  .bg-columns { grid-template-columns: 1fr; gap: 0.5rem; }

  /* Two result cards per row instead of 4 */
  .bg-results__cards { grid-template-columns: repeat(2, 1fr); gap: 0.35rem; }

  .bg-card {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* Compact sections for print */
  .bg-section { margin-bottom: 0.35rem; }
  .bg-section__header { padding: 0.35rem 0.5rem; }
  .bg-section__header h2 { font-size: 0.9rem; }

  .bg-row { padding: 0.15rem 0; gap: 0.25rem; }
  .bg-row label { font-size: 8pt; }

  .bg-input {
    border: none !important;
    background: none !important;
    padding: 0 !important;
    font-weight: 600;
    font-size: 8pt;
    width: 80px;
  }

  .bg-liab-row--omitted { opacity: 0.5; }

  /* Results section should stay together */
  .bg-results {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}
