/* ── Reset & Basis ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #f4f6f9;
  --surface:     #ffffff;
  --border:      #e2e8f0;
  --text:        #2d3748;
  --text-muted:  #718096;
  --primary:     #4a6cf7;
  --primary-h:   #3a5ce5;
  --success:     #38a169;
  --danger:      #e53e3e;
  --warning:     #d97706;
  --income-bg:   #f0fff4;
  --income-bd:   #9ae6b4;
  --ueber-bg:    #fffbeb;
  --ueber-bd:    #f6e05e;
  --positive:    #276749;
  --negative:    #c53030;
  --radius:      10px;
  --shadow:      0 2px 12px rgba(0,0,0,.08);
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Container ─────────────────────────────────────────────────────────────── */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.app-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary);
}

.month-select {
  padding: .45rem .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: .95rem;
  cursor: pointer;
  color: var(--text);
}

.header-actions {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .45rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, transform .1s;
}
.btn:active { transform: scale(.97); }

.btn-primary   { background: var(--primary);  color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-secondary { background: #edf2f7; color: var(--text); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #b45309; }

.btn-icon {
  background: none;
  border: none;
  font-size: 1.05rem;
  cursor: pointer;
  padding: .2rem .35rem;
  border-radius: 6px;
  transition: background .15s;
  line-height: 1;
}
.btn-add:hover    { background: #c6f6d5; }
.btn-danger:hover { background: #fed7d7; }

.btn-danger-outline {
  background: #fff5f5;
  color: var(--danger);
  border: 1.5px solid var(--danger);
}
.btn-danger-outline:hover {
  background: var(--danger);
  color: #fff;
}

/* ── Tabelle ───────────────────────────────────────────────────────────────── */
.table-wrapper {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.budget-table {
  width: 100%;
  border-collapse: collapse;
}

.budget-table thead th {
  background: var(--primary);
  color: #fff;
  padding: .75rem 1rem;
  text-align: right;
  font-weight: 600;
  font-size: .95rem;
}
.budget-table thead th.col-name { text-align: left; }
.budget-table thead th.col-action { width: 80px; }

/* Spaltenbreiten */
.col-name   { width: 40%; }
.col-plan   { width: 17%; }
.col-ist    { width: 17%; }
.col-rest   { width: 17%; }
.col-action { width: 9%;  }

.budget-table td {
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--border);
  text-align: right;
  vertical-align: middle;
  font-size: .95rem;
}
.budget-table td.col-name { text-align: left; }
.budget-table td.col-action { text-align: center; }

/* Zeilen-Hover */
.budget-row:hover { background: #f7fafc; }

/* Einnahmen-Zeilen */
.row-income {
  background: var(--income-bg);
  border-left: 3px solid var(--income-bd);
}
.row-income:hover { background: #e6ffed; }

.row-uebertrag {
  background: var(--ueber-bg);
  border-left: 3px solid var(--ueber-bd);
}
.row-uebertrag:hover { background: #fefce8; }

/* Plan-Wert editierbar */
.plan-value {
  cursor: pointer;
  padding: .2rem .4rem;
  border-radius: 5px;
  transition: background .15s;
  display: inline-block;
}
.plan-value:hover {
  background: #ebf4ff;
  outline: 1px dashed var(--primary);
}

/* Ist-Wert klickbar */
.ist-value {
  cursor: pointer;
  padding: .2rem .4rem;
  border-radius: 5px;
  transition: background .15s;
  display: inline-block;
  color: var(--text);
}
.ist-value:hover { background: #fff5f5; }

/* Rest */
.rest-cell { font-weight: 600; }
.positive  { color: var(--positive); }
.negative  { color: var(--negative); }

.dimmed { color: var(--text-muted); }

/* Inline-Input */
.inline-input {
  width: 100px;
  padding: .25rem .4rem;
  border: 1px solid var(--primary);
  border-radius: 5px;
  font-size: .9rem;
  text-align: right;
  outline: none;
}

/* ── Summenzeile ───────────────────────────────────────────────────────────── */
.sum-row {
  background: #edf2f7;
  border-top: 2px solid var(--border);
}
.sum-row td {
  padding: .75rem 1rem;
  font-size: 1rem;
}

/* ── Legende ───────────────────────────────────────────────────────────────── */
.legend {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  font-size: .82rem;
  color: var(--text-muted);
}
.legend-item { display: flex; align-items: center; gap: .4rem; }
.dot {
  width: 10px; height: 10px; border-radius: 50%; display: inline-block;
}
.dot-plan { background: var(--primary); }
.dot-ist  { background: var(--danger); }
.dot-neg  { background: var(--negative); }

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
  width: 100%;
  max-width: 540px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-sm { max-width: 360px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
  background: var(--primary);
  color: #fff;
}
.modal-header h3 { font-size: 1.05rem; font-weight: 700; }

.modal-close {
  background: none; border: none; color: #fff;
  font-size: 1.2rem; cursor: pointer; padding: .1rem .3rem;
  border-radius: 4px; transition: background .15s;
}
.modal-close:hover { background: rgba(255,255,255,.2); }

.modal-body {
  padding: 1.2rem;
  overflow-y: auto;
  flex: 1;
}
.modal-body h4 {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: .6rem;
}

/* Form-Row */
.form-row {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
}
.form-row input {
  flex: 1;
  min-width: 100px;
  padding: .45rem .7rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: .9rem;
  outline: none;
  transition: border-color .15s;
}
.form-row input:focus { border-color: var(--primary); }

/* Ausgaben-Liste */
.expense-list { display: flex; flex-direction: column; gap: .5rem; }

.expense-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .7rem;
  background: #f7fafc;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: .88rem;
}
.exp-date   { color: var(--text-muted); min-width: 70px; }
.exp-amount { font-weight: 700; color: var(--danger); min-width: 70px; text-align: right; }
.exp-desc   { flex: 1; color: var(--text); }

.empty-hint {
  color: var(--text-muted);
  font-size: .88rem;
  text-align: center;
  padding: 1rem;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .app-header { flex-direction: column; align-items: flex-start; }
  .col-rest { display: none; }
  .budget-table thead th:nth-child(4) { display: none; }
  .budget-table td.col-rest { display: none; }
}
