/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #000000;
  --bg-dark: #0d1117;
  --card: #111827;
  --gray-bar: #c8cdd6;
  --gray-bar-dark: #9aa0ab;
  --text: #e8eaed;
  --text-muted: #8b98a9;
  --green: #27ae60;
  --red: #e74c3c;
  --blue: #2980b9;
  --shadow: 0 2px 12px rgba(0,0,0,0.1);
  --radius: 10px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== HEADER ===== */
.site-header {
  background: var(--bg-dark);
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.site-header h1 {
  font-size: clamp(1rem, 3vw, 1.5rem);
  font-weight: 700;
  flex: 1;
}
.haushalt-gap {
  display: inline-block;
  background: #e74c3c;
  color: white;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 12px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.header-icon-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 1rem;
  cursor: pointer;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  line-height: 1;
}
.header-icon-btn:hover { background: rgba(255,255,255,0.16); }

/* ===== MAIN LAYOUT ===== */
.main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

/* ===== INCOME BAR SECTION ===== */
.income-section {
  width: 100%;
  background: transparent;
  padding: 24px 0 20px;
  margin-bottom: 0;
}
.income-inner {
  max-width: 100%;
  padding: 0 24px;
}

.income-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}

.income-label {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}
.income-label span {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.85rem;
  margin-left: 6px;
  opacity: 0.8;
}

.gear-btn {
  background: none;
  border: 1.5px solid #2d3748;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s;
  white-space: nowrap;
}
.gear-btn:hover { background: #1a2332; border-color: #4a5568; color: var(--text); }

/* Drop zone / budget bar */
.budget-bar-wrap {
  position: relative;
  background: #2a2d3e;
  border-radius: 10px;
  height: 30vh;
  overflow: hidden;
  border: 2px solid transparent;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.budget-bar-wrap.drag-over {
  border-color: #3498db;
  background: #0d1f2d;
}
.budget-bar-wrap.drop-hint {
  animation: pulse-border 1s ease-in-out infinite alternate;
}
@keyframes pulse-border {
  from { border-color: transparent; }
  to   { border-color: #4a6070; }
}
.budget-bar-wrap.is-overflow {
  border-color: rgba(231,76,60,0.6);
  box-shadow: 0 0 18px rgba(231,76,60,0.25);
}

.budget-bar-overflow {
  display: none;
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  background: rgba(231,76,60,0.45);
  border-left: 2px solid rgba(231,76,60,0.9);
  align-items: center;
  justify-content: flex-end;
  padding-right: 14px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
.budget-bar-overflow.visible {
  display: flex;
}

.budget-bar-fill {
  display: flex;
  height: 100%;
  transition: width 0.4s ease;
}

.budget-segment {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: white;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
  min-width: 2px;
  overflow: hidden;
  white-space: nowrap;
  cursor: pointer;
  transition: filter 0.15s;
}
.budget-segment:hover { filter: brightness(1.1); }

.budget-bar-label {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.8rem;
  font-weight: 600;
  color: rgba(255,255,255,0.45);
  pointer-events: none;
}

.drop-hint-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  color: rgba(255,255,255,0.3);
  pointer-events: none;
}

/* Status bar */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.status-numbers {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.status-numbers strong {
  color: var(--text);
}

.balance-badge {
  font-size: 0.9rem;
  font-weight: 700;
  padding: 5px 14px;
  border-radius: 20px;
  white-space: nowrap;
}
.balance-badge.deficit { background: rgba(231,76,60,0.15); color: #ff6b6b; border: 1px solid rgba(231,76,60,0.3); }
.balance-badge.surplus { background: rgba(39,174,96,0.15); color: #4ade80; border: 1px solid rgba(39,174,96,0.3); }
.balance-badge.balanced { background: rgba(39,174,96,0.15); color: #4ade80; border: 1px solid rgba(39,174,96,0.3); }

/* ===== BLOCKS POOL ===== */
.pool-section h2 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
  margin-top: 8px;
}

.blocks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.block-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
  cursor: grab;
  position: relative;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s;
  border: 2.5px solid rgba(255,255,255,0.06);
  user-select: none;
  -webkit-user-select: none;
}
.block-card:active { cursor: grabbing; }
.block-card.dragging { opacity: 0.5; transform: scale(0.97); }
.block-card.in-budget {
  border-color: currentColor;
  opacity: 0.6;
}
.block-card.in-budget::after {
  content: '✓ im Haushalt';
  position: absolute;
  top: 6px;
  right: 34px;
  font-size: 0.65rem;
  font-weight: 600;
  background: rgba(255,255,255,0.1);
  padding: 2px 6px;
  border-radius: 8px;
}

.block-color-bar {
  height: 4px;
  border-radius: 2px;
  margin-bottom: 10px;
}

.block-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}

.block-icon { font-size: 1.3rem; line-height: 1; }

.block-name {
  font-size: 0.9rem;
  font-weight: 600;
  flex: 1;
  line-height: 1.3;
}

.block-gear-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 2px;
  opacity: 0.5;
  transition: opacity 0.15s;
  line-height: 1;
  flex-shrink: 0;
}
.block-gear-btn:hover { opacity: 1; }

.block-mrd {
  margin-top: 8px;
  font-size: 1.25rem;
  font-weight: 700;
}
.block-mrd-orig {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.block-mrd-mod {
  font-size: 0.75rem;
  font-weight: 600;
  margin-left: 4px;
}
.mod-plus { color: var(--red); }
.mod-minus { color: var(--green); }

.block-tap-hint {
  margin-top: 8px;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ===== CTA BUTTON ===== */
.cta-wrap {
  text-align: center;
  margin: 32px 0 24px;
}

.btn-cta {
  background: linear-gradient(135deg, #1a6b3a 0%, #27ae60 100%);
  color: white;
  font-size: 1.15rem;
  font-weight: 700;
  padding: 18px 40px;
  border-radius: 50px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 24px rgba(39,174,96,0.3);
  transition: transform 0.15s, box-shadow 0.15s;
  letter-spacing: 0.01em;
}
.btn-cta:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(39,174,96,0.45);
}
.btn-cta:active { transform: translateY(0); }

@keyframes cta-pulse {
  0%   { transform: scale(1); box-shadow: 0 4px 24px rgba(39,174,96,0.3); }
  30%  { transform: scale(1.07); box-shadow: 0 8px 36px rgba(39,174,96,0.55); }
  60%  { transform: scale(1); box-shadow: 0 4px 24px rgba(39,174,96,0.3); }
  80%  { transform: scale(1.05); box-shadow: 0 8px 32px rgba(39,174,96,0.5); }
  100% { transform: scale(1); box-shadow: 0 4px 24px rgba(39,174,96,0.3); }
}
.btn-cta-pulse {
  animation: cta-pulse 0.9s ease-in-out 3;
}

/* ===== ACTIONS ===== */
.actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
  flex-wrap: wrap;
}

.btn {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}
.btn-primary { background: var(--bg-dark); color: white; }
.btn-primary:hover { background: #263548; }
.btn-secondary { background: #1a2332; color: var(--text); border: 1.5px solid #2d3748; }
.btn-secondary:hover { background: #263548; }
.btn-share { background: #27ae60; color: white; }
.btn-share:hover { background: #219a52; }

/* ===== LIGHTBOX / MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: #111827;
  width: 100%;
  max-width: 600px;
  border-radius: 20px 20px 0 0;
  max-height: 85vh;
  overflow-y: hidden;
  display: flex;
  flex-direction: column;
  transform: translateY(40px);
  transition: transform 0.25s ease;
}
.modal-overlay.open .modal { transform: translateY(0); }

@media (min-width: 600px) {
  .modal-overlay { align-items: center; padding: 16px; }
  .modal { border-radius: 16px; max-height: 80vh; }
}

.modal-sticky-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid #1f2937;
  flex-shrink: 0;
  background: #111827;
  border-radius: 20px 20px 0 0;
}

@media (min-width: 600px) {
  .modal-sticky-header { border-radius: 16px 16px 0 0; }
}

.modal-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-body {
  overflow-y: auto;
  padding: 20px 20px 32px;
  flex: 1;
}
.modal-body p {
  font-size: 0.92rem;
  line-height: 1.75;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.modal-body p:last-child { margin-bottom: 0; }

.modal-handle {
  width: 40px;
  height: 4px;
  background: #2d3748;
  border-radius: 2px;
  margin: 0 auto 16px;
}

.modal-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}
.modal-title h3 { font-size: 1.2rem; font-weight: 700; }
.modal-icon { font-size: 1.5rem; }

.modal-mrd {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 4px;
}
.modal-mrd span { font-size: 1rem; font-weight: 400; color: var(--text-muted); }

.modal-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 8px;
}

.modal-source {
  font-size: 0.75rem;
  margin-bottom: 20px;
}
.modal-source a { color: #3498db; text-decoration: none; }
.modal-source a:hover { text-decoration: underline; }

.modal-divider {
  border: none;
  border-top: 1px solid #1f2937;
  margin: 16px 0;
}

.sliders-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.slider-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid #1f2937;
  gap: 12px;
}
.slider-item:last-child { border-bottom: none; }

.slider-sub-item {
  background: rgba(39,174,96,0.06);
  border-left: 3px solid rgba(39,174,96,0.4);
  padding-left: 14px;
  margin-left: 12px;
  border-radius: 0 6px 6px 0;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.slider-info { flex: 1; }
.slider-text {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}
.slider-detail {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 4px;
}
.slider-delta {
  font-size: 0.8rem;
  font-weight: 700;
}
.slider-delta.plus { color: var(--red); }
.slider-delta.minus { color: var(--green); }
.slider-source {
  font-size: 0.7rem;
}
.slider-source a { color: #3498db; text-decoration: none; }

/* Toggle switch */
.toggle-wrap { flex-shrink: 0; }
.toggle {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #2d3748;
  border-radius: 26px;
  transition: .2s;
}
.toggle-slider:before {
  content: '';
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle input:checked + .toggle-slider { background: #27ae60; }
.toggle input:checked + .toggle-slider:before { transform: translateX(20px); }

.modal-close {
  background: #27ae60;
  border: none;
  border-radius: 8px;
  padding: 6px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  white-space: nowrap;
  flex-shrink: 0;
}
.modal-close:hover { background: #2ecc71; }

/* ===== BAR TOOLTIP ===== */
#bar-tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 3000;
  background: #1e2a3a;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 7px 13px;
  font-size: 0.85rem;
  color: var(--text);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.12s, transform 0.12s;
}
#bar-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}
.bar-tooltip-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.bar-tooltip-mrd {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-left: 2px;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-dark);
  color: white;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 2000;
  transition: transform 0.3s ease;
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ===== EVAL SECTION (hidden until used) ===== */
.eval-section {
  display: none;
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
  margin-top: 24px;
}
.eval-section.visible { display: block; }

.eval-title { font-size: 1rem; font-weight: 700; margin-bottom: 16px; }
.eval-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.eval-box {
  background: #0d1117;
  border-radius: 8px;
  padding: 14px;
}
.eval-box-label { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 4px; }
.eval-box-val { font-size: 1.4rem; font-weight: 800; }
.eval-list { margin-top: 16px; }
.eval-list h4 { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); margin-bottom: 8px; }
.eval-list ul { list-style: none; }
.eval-list li {
  font-size: 0.85rem;
  padding: 4px 0;
  border-bottom: 1px solid #1f2937;
  display: flex;
  justify-content: space-between;
}
.eval-list li:last-child { border-bottom: none; }

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
  .blocks-grid { grid-template-columns: 1fr 1fr; }
  .block-name { font-size: 0.82rem; }
  .block-mrd { font-size: 1.1rem; }
  .budget-bar-wrap { height: 30vh; }
  .income-inner { padding: 0 12px; }
}

@media (min-width: 768px) {
  .blocks-grid { grid-template-columns: repeat(3, 1fr); }
}
