/**
 * Modul: Budget-Tracker (Budget)
 * Zweck: Styles für Monatsübersicht, Balkendiagramm, Transaktionsliste, Modal
 * Abhängigkeiten: tokens.css, layout.css
 */

/* --------------------------------------------------------
 * Modul-Akzent
 * -------------------------------------------------------- */
.budget-page { --module-accent: var(--module-budget); }

/* --------------------------------------------------------
 * Seiten-Layout
 * -------------------------------------------------------- */
.budget-page {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--safe-area-inset-top) - var(--nav-bottom-height) - var(--safe-area-inset-bottom));
  max-width: var(--content-max-width);
  margin: 0 auto;
  overflow: hidden;
}

@media (min-width: 1024px) {
  .budget-page { height: 100dvh; }
}

@media (max-width: 640px) {
  .budget-nav {
    flex-wrap: wrap;
  }

  .budget-nav__label {
    order: 3;
    flex-basis: 100%;
  }

  .budget-tabs {
    margin-left: auto;
  }
}

/* --------------------------------------------------------
 * Monat-Navigation
 * -------------------------------------------------------- */
.budget-nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 3px solid var(--module-accent);
  border-bottom: 1px solid var(--color-border);
  background-color: var(--color-surface);
  flex-shrink: 0;
}

.budget-nav__label {
  font-size: var(--text-base);
  font-weight: var(--font-weight-semibold);
  flex: 1;
  text-align: center;
}

.budget-nav__today {
  font-size: var(--text-sm);
  color: var(--color-accent);
  font-weight: var(--font-weight-medium);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--color-accent-light);
  cursor: pointer;
  border: none;
  white-space: nowrap;
}

.budget-tabs {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
}

.budget-tab {
  min-height: 40px;
  padding: 0 var(--space-2);
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
}

.budget-tab--active {
  color: var(--color-text-on-accent);
}

.budget-tab[data-tab="budget"].budget-tab--active {
  background: var(--module-budget);
}

.budget-tab[data-tab="loans"].budget-tab--active {
  background: var(--color-info);
}

.budget-tab-panel {
  flex: 1;
  min-height: 0;
}

.budget-tab-panel--budget {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.budget-tab-panel--loans {
  overflow-y: auto;
  padding-top: var(--space-3);
}

/* --------------------------------------------------------
 * Zusammenfassungs-Karten
 * -------------------------------------------------------- */
.budget-summary {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  flex-shrink: 0;
}

@media (min-width: 480px) {
  .budget-summary {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-3);
  }
}

.budget-summary-card {
  background-color: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  box-shadow: var(--shadow-sm);
  text-align: center;
}

.budget-summary-card__label {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-1);
}

.budget-summary-card__amount {
  font-size: var(--text-xl);
  font-weight: var(--font-weight-bold);
  font-variant-numeric: tabular-nums;
}

.budget-summary-card--income   .budget-summary-card__amount { color: var(--color-success); }
.budget-summary-card--expenses .budget-summary-card__amount { color: var(--color-danger);  }
.budget-summary-card--balance  .budget-summary-card__amount { color: var(--color-text-primary); }
.budget-summary-card--balance-positive .budget-summary-card__amount { color: var(--color-success); }
.budget-summary-card--balance-negative .budget-summary-card__amount { color: var(--color-danger);  }

.budget-summary-card__trend {
  font-size: var(--text-xs);
  margin-top: var(--space-1);
}
.budget-summary-card__trend--positive { color: var(--color-success); }
.budget-summary-card__trend--negative { color: var(--color-danger);  }
.budget-summary-card__trend--neutral  { color: var(--color-text-secondary); }

/* --------------------------------------------------------
 * Kategorien-Diagramm (Canvas)
 * -------------------------------------------------------- */
.budget-chart-section {
  padding: 0 var(--space-4) var(--space-3);
  flex-shrink: 0;
}

.budget-chart-section__title {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.budget-chart {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.budget-bar-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.budget-bar-row__label {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  width: 90px;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.budget-bar-row__track {
  flex: 1;
  height: var(--space-2);
  background-color: var(--color-surface-2);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.budget-bar-row__fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width var(--transition-slow);
}

.budget-bar-row__fill--income   { background-color: var(--color-success); }
.budget-bar-row__fill--expenses { background-color: var(--color-danger);  }

.budget-bar-row__amount {
  font-size: var(--text-xs);
  font-weight: var(--font-weight-medium);
  font-variant-numeric: tabular-nums;
  width: 64px;
  text-align: right;
  flex-shrink: 0;
}

/* --------------------------------------------------------
 * Empréstimos
 * -------------------------------------------------------- */
.budget-loans {
  margin: 0 var(--space-4) var(--space-3);
  padding: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.budget-loans__header,
.budget-loan-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.budget-loans__eyebrow {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.budget-loans__summary {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-top: 2px;
}

.budget-loans__filters {
  display: flex;
  gap: var(--space-1);
  padding: 2px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
}

.budget-loans__filter {
  min-height: 30px;
  padding: 0 var(--space-2);
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  font-size: var(--text-xs);
  font-weight: var(--font-weight-medium);
}

.budget-loans__filter i {
  width: 14px;
  height: 14px;
  margin-right: 4px;
  vertical-align: -2px;
}

.budget-loans__filter--active {
  background: var(--color-info);
  color: var(--color-text-on-accent);
}

.budget-loans__stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.budget-loans__stats > div {
  min-width: 0;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
}

.budget-loans__stats span,
.budget-loan-card__amounts span,
.budget-loan-card__meta,
.budget-loan-card__footer > span {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
}

.budget-loans__stats strong,
.budget-loan-card__amounts strong {
  display: block;
  font-size: var(--text-base);
  font-variant-numeric: tabular-nums;
  color: var(--color-text-primary);
  margin-top: 2px;
  white-space: nowrap;
}

.budget-loans__list {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-2);
  margin-top: var(--space-3);
  max-height: min(58dvh, 640px);
  overflow-y: auto;
  padding-right: var(--space-1);
}

.budget-loans__empty {
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  padding: var(--space-3) 0 0;
}

.budget-loan-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--transition-fast), background-color var(--transition-fast), transform var(--transition-fast);
}

.budget-loan-card:hover {
  border-color: var(--color-info);
  background: var(--color-surface-2);
}

.budget-loan-card__main {
  min-width: 0;
}

.budget-loan-card__title {
  font-size: var(--text-base);
  font-weight: var(--font-weight-semibold);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.budget-loan-card__title-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.budget-loan-card__filter {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  color: var(--color-text-secondary);
  cursor: pointer;
}

.budget-loan-card__filter:hover {
  color: var(--module-accent);
  border-color: var(--module-accent);
}

.budget-loan-card__filter--active {
  color: var(--color-text-on-accent);
  border-color: var(--color-info);
  background: var(--color-info);
}

.budget-loan-card__filter i {
  width: 15px;
  height: 15px;
}

.budget-loan-card__amounts {
  text-align: right;
}

.budget-loan-card__progress {
  grid-column: 1 / -1;
  height: 6px;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--color-surface-2);
}

.budget-loan-card__progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--color-success);
}

.budget-loan-card__footer {
  grid-column: 1 / -1;
}

.budget-loan-card__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.budget-loan-transactions {
  margin-top: var(--space-4);
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-3);
}

.budget-loan-transactions__title,
.loan-report__section-title {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-2);
}

.budget-loan-transactions__list,
.loan-report__transactions {
  display: grid;
  gap: var(--space-2);
}

.budget-loan-transaction {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
}

.budget-loan-transaction span {
  display: block;
  margin-top: 2px;
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
}

.budget-loan-transaction > div:last-child {
  text-align: right;
}

.loan-report__hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
}

.loan-report__borrower {
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

.loan-report__title {
  font-size: var(--text-xl);
  font-weight: var(--font-weight-bold);
  margin-top: 2px;
}

.loan-report__status {
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semibold);
}

.loan-report__status--active {
  background: var(--color-info);
  color: var(--color-text-on-accent);
}

.loan-report__status--paid {
  background: var(--color-success);
  color: var(--color-text-on-accent);
}

.loan-report__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
  margin: var(--space-3) 0;
}

.loan-report__grid > div {
  padding: var(--space-3);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
}

.loan-report__grid span {
  display: block;
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  margin-bottom: 2px;
}

.budget-page .form-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

@media (max-width: 560px) {
  .budget-loans__header,
  .budget-loan-card__footer {
    align-items: stretch;
    flex-direction: column;
  }

  .budget-loans__stats {
    grid-template-columns: 1fr;
  }

  .budget-loan-card {
    grid-template-columns: 1fr;
  }

  .budget-loan-card__amounts {
    text-align: left;
  }

  .budget-loan-card__actions {
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .budget-page .form-grid-2 {
    grid-template-columns: 1fr;
  }
}

/* --------------------------------------------------------
 * Transaktions-Liste
 * -------------------------------------------------------- */
.budget-list-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-top: 1px solid var(--color-border);
  min-height: 0;
}

.budget-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4) var(--space-2);
  flex-shrink: 0;
  border-top: 3px solid var(--module-accent);
}

.budget-list-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.budget-list-header__filter {
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  margin-top: 2px;
}

.budget-list-header__title {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.budget-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.budget-list,
.budget-loans__list,
.budget-tab-panel--loans {
  scrollbar-width: thin;
  scrollbar-color: var(--module-accent) transparent;
}

.budget-list::-webkit-scrollbar,
.budget-loans__list::-webkit-scrollbar,
.budget-tab-panel--loans::-webkit-scrollbar {
  width: 10px;
}

.budget-list::-webkit-scrollbar-track,
.budget-loans__list::-webkit-scrollbar-track,
.budget-tab-panel--loans::-webkit-scrollbar-track {
  background: transparent;
}

.budget-list::-webkit-scrollbar-thumb,
.budget-loans__list::-webkit-scrollbar-thumb,
.budget-tab-panel--loans::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--module-accent) 55%, transparent);
  border: 3px solid transparent;
  border-radius: var(--radius-full);
  background-clip: padding-box;
}

.budget-entry {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border-subtle);
  border-left: 3px solid var(--module-accent);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.budget-entry:hover {
  background-color: var(--color-surface-2);
}

.budget-entry__indicator {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.budget-entry__indicator--income   { background-color: var(--color-success); }
.budget-entry__indicator--expenses { background-color: var(--color-danger);  }

.budget-entry__body {
  flex: 1;
  min-width: 0;
}

.budget-entry__title {
  font-size: var(--text-base);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.budget-entry__meta {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-top: 1px;
}

.budget-entry__amount {
  font-size: var(--text-base);
  font-weight: var(--font-weight-semibold);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.budget-entry__amount--income   { color: var(--color-success); }
.budget-entry__amount--expenses { color: var(--color-danger);  }

.budget-entry__delete {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-disabled);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition-fast), color var(--transition-fast);
  position: relative;
}

.budget-entry__actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
}

.budget-entry__delete::before {
  content: '';
  position: absolute;
  inset: -10px;
}

.budget-entry:hover .budget-entry__delete {
  opacity: 1;
}

.budget-entry--loan .budget-entry__delete {
  opacity: 1;
}

.budget-entry__delete:hover {
  color: var(--color-danger);
}


/* --------------------------------------------------------
 * Budget-Modal Content-Styles (Overlay/Panel via shared modal.js)
 * -------------------------------------------------------- */

/* Einnahme/Ausgabe-Toggle */
.amount-type-toggle {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
  background-color: var(--color-surface-2);
  border-radius: var(--radius-sm);
  padding: var(--space-0h);
}

.amount-type-toggle--entry-only {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.amount-type-btn {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-xs);
  border: none;
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  background: none;
  color: var(--color-text-secondary);
  transition: all var(--transition-fast);
  min-height: var(--target-lg);
}

.amount-type-btn--income.amount-type-btn--active {
  background-color: var(--color-success);
  color: var(--color-text-on-accent);
}

.amount-type-btn--expenses.amount-type-btn--active {
  background-color: var(--color-danger);
  color: var(--color-text-on-accent);
}

.amount-type-btn--loan.amount-type-btn--active {
  background-color: var(--module-budget);
  color: var(--color-text-on-accent);
}

.modal-panel .js-entry-field[hidden],
.modal-panel #bm-loan-fields[hidden] {
  display: none !important;
}

.budget-field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
}

.budget-field-header .form-label {
  margin-bottom: 0;
}

.budget-inline-add {
  min-height: auto;
  padding: 2px var(--space-2);
  font-size: var(--text-xs);
}

.budget-inline-modal {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: rgba(0, 0, 0, 0.38);
}

.budget-inline-modal__panel {
  width: min(100%, 380px);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-lg);
}

.budget-inline-modal__header,
.budget-inline-modal__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.budget-inline-modal__header {
  margin-bottom: var(--space-3);
}

.budget-inline-modal__footer {
  justify-content: flex-end;
}
