/* Budget-Ampel — eigenes Design: neutrales Grau + Ampel-Status (Grün/Gelb/Rot) */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eceef1;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #d7dbe0;
  --shadow: 0 1px 2px rgba(17, 24, 39, .06), 0 6px 18px rgba(17, 24, 39, .07);

  --accent: #374151;
  --accent-contrast: #ffffff;

  --green: #16a34a;
  --green-soft: #dcfce7;
  --yellow: #d97706;
  --yellow-soft: #fef3c7;
  --red: #dc2626;
  --red-soft: #fee2e2;

  --lamp-off: #cbd1d9;

  --radius: 14px;
  --radius-sm: 10px;
  --gap: 16px;
  --maxw: 560px;

  --focus: #2563eb;
}

[data-theme="dark"] {
  --bg: #14171c;
  --surface: #1d222a;
  --surface-2: #262c36;
  --text: #e8ebef;
  --text-muted: #9aa3af;
  --border: #333b46;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 22px rgba(0, 0, 0, .35);

  --accent: #e8ebef;
  --accent-contrast: #14171c;

  --green: #22c55e;
  --green-soft: #133a23;
  --yellow: #f59e0b;
  --yellow-soft: #3a2c0c;
  --red: #ef4444;
  --red-soft: #3a1717;

  --lamp-off: #39414d;

  --focus: #60a5fa;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  line-height: 1.45;
}

body {
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  z-index: 100;
}
.skip-link:focus { left: 8px; top: 8px; }

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 1.15rem; margin: 0; letter-spacing: .2px; }
.brand-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: linear-gradient(180deg, var(--red), var(--yellow) 50%, var(--green));
  box-shadow: 0 0 0 3px var(--surface-2);
}

.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--gap);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.card-title { font-size: 1rem; margin: 0 0 12px; }

/* Buttons */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  cursor: pointer;
  width: 100%;
  transition: filter .15s ease, transform .05s ease, background .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { filter: brightness(0.97); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { filter: brightness(1.05); }

.icon-btn {
  font: inherit;
  font-size: 1.25rem;
  line-height: 1;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 42px; height: 42px;
  min-width: 42px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { filter: brightness(0.97); }

.link-btn {
  font: inherit;
  font-size: .8rem;
  background: none;
  border: none;
  color: var(--text-muted);
  text-decoration: underline;
  cursor: pointer;
  padding: 2px 0;
}
.link-btn:hover { color: var(--text); }

/* Month bar */
.month-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
}
.month-label { text-align: center; display: flex; flex-direction: column; gap: 2px; }
.month-label #monthName { font-weight: 700; font-size: 1.05rem; }

/* Ampel */
.ampel-card { text-align: center; }
.ampel {
  display: inline-flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 22px;
  background: var(--surface-2);
  border-radius: 20px;
  border: 1px solid var(--border);
}
.lamp {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--lamp-off);
  box-shadow: inset 0 4px 10px rgba(0,0,0,.25);
  transition: background .25s ease, box-shadow .25s ease, opacity .25s ease;
  opacity: .35;
}
.ampel[data-active="red"] .lamp-red {
  background: var(--red); opacity: 1;
  box-shadow: 0 0 22px 4px var(--red), inset 0 2px 6px rgba(255,255,255,.25);
}
.ampel[data-active="yellow"] .lamp-yellow {
  background: var(--yellow); opacity: 1;
  box-shadow: 0 0 22px 4px var(--yellow), inset 0 2px 6px rgba(255,255,255,.25);
}
.ampel[data-active="green"] .lamp-green {
  background: var(--green); opacity: 1;
  box-shadow: 0 0 22px 4px var(--green), inset 0 2px 6px rgba(255,255,255,.25);
}
.status-text {
  margin: 16px 0 0;
  font-weight: 600;
  font-size: 1.05rem;
}
.status-text.is-green { color: var(--green); }
.status-text.is-yellow { color: var(--yellow); }
.status-text.is-red { color: var(--red); }

/* Overview */
.numbers {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.num-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
  min-width: 0;
}
.num-label { display: block; font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.num-value { display: block; font-weight: 700; font-size: 1rem; margin-top: 4px; overflow-wrap: anywhere; }
.num-rest .num-value.is-green { color: var(--green); }
.num-rest .num-value.is-yellow { color: var(--yellow); }
.num-rest .num-value.is-red { color: var(--red); }

.progress {
  height: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--green);
  border-radius: 999px;
  transition: width .4s ease, background .3s ease;
}
.progress-bar.is-yellow { background: var(--yellow); }
.progress-bar.is-red { background: var(--red); }
.progress-info { margin: 8px 0 14px; font-size: .85rem; color: var(--text-muted); text-align: center; }

/* Form */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
}
.field input::placeholder { color: var(--text-muted); }
.field-error {
  margin: 6px 0 0;
  color: var(--red);
  font-size: .8rem;
}

/* List */
.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.list-head .card-title { margin: 0; }
.count-badge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: .8rem;
  font-weight: 700;
  color: var(--text-muted);
}
.expense-list { list-style: none; margin: 0; padding: 0; }
.expense-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.expense-item:last-child { border-bottom: none; }
.exp-main { flex: 1; min-width: 0; }
.exp-cat { font-weight: 600; overflow-wrap: anywhere; }
.exp-meta { font-size: .78rem; color: var(--text-muted); }
.exp-amount { font-weight: 700; white-space: nowrap; }
.del-btn {
  background: var(--red-soft);
  color: var(--red);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  width: 38px; height: 38px;
  min-width: 38px;
  font-size: 1.1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.del-btn:hover { filter: brightness(0.96); }
.empty-state { color: var(--text-muted); text-align: center; padding: 8px 0; margin: 0; }
.empty-state[hidden] { display: none; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 22, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 50;
  animation: fade .15s ease;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 420px;
  padding: 20px;
  animation: pop .18s ease;
}
.modal-title { margin: 0 0 14px; font-size: 1.1rem; }
.modal-message { margin: 0 0 18px; color: var(--text); }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { width: auto; flex: 1; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

/* Toast */
.toast-wrap {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  z-index: 60;
  pointer-events: none;
}
.toast {
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: .9rem;
  max-width: var(--maxw);
  animation: toastIn .2s ease;
}
.toast.is-out { animation: toastOut .25s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(12px); } }

/* Focus visibility */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Theme toggle icon */
[data-theme="dark"] .theme-icon { transform: rotate(180deg); display: inline-block; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

@media (max-width: 360px) {
  .num-value { font-size: .9rem; }
  .lamp { width: 60px; height: 60px; }
}
