/* ============================================================
   Spar-Ziel — eigenes Design
   Palette: Smaragdgrün #059669 + Gold-Akzent
   ============================================================ */

:root {
  --emerald: #059669;
  --emerald-600: #047857;
  --emerald-400: #10b981;
  --emerald-300: #34d399;
  --gold: #d4af37;
  --gold-soft: #f1d68a;
  --gold-deep: #b8860b;

  --bg: #f3faf7;
  --bg-grad-a: #ecfdf5;
  --bg-grad-b: #f0fdfa;
  --surface: #ffffff;
  --surface-2: #f6fbf9;
  --surface-3: #eef6f2;
  --border: #d8e9e2;
  --border-strong: #bcdacf;

  --text: #0f2e25;
  --text-soft: #44675c;
  --text-muted: #6e8a80;

  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --success: #059669;
  --warn: #d97706;

  --track: #e2efe9;

  --shadow-sm: 0 1px 2px rgba(5, 70, 50, 0.06);
  --shadow-md: 0 6px 18px rgba(5, 70, 50, 0.10);
  --shadow-lg: 0 18px 48px rgba(5, 70, 50, 0.18);

  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 22px;

  --maxw: 880px;
  --header-h: 60px;

  --focus: 0 0 0 3px rgba(5, 150, 105, 0.35);
}

[data-theme="dark"] {
  --emerald: #10b981;
  --emerald-600: #34d399;
  --emerald-400: #34d399;
  --emerald-300: #6ee7b7;
  --gold: #e6c560;
  --gold-soft: #6b5b1f;
  --gold-deep: #f0d678;

  --bg: #06140f;
  --bg-grad-a: #07181210;
  --bg-grad-b: #06140f;
  --surface: #0e221b;
  --surface-2: #122a22;
  --surface-3: #16332a;
  --border: #1d3b31;
  --border-strong: #2a5044;

  --text: #e7f5ef;
  --text-soft: #a7c6bb;
  --text-muted: #79988c;

  --danger: #f87171;
  --danger-bg: #2a1414;
  --success: #34d399;
  --warn: #fbbf24;

  --track: #173329;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.6);

  --focus: 0 0 0 3px rgba(52, 211, 153, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 100% -10%, var(--bg-grad-a), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, var(--bg-grad-b), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--emerald);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 200;
}
.skip-link:focus { left: 0; }

/* ---------------- Header ---------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: linear-gradient(120deg, var(--emerald-600), var(--emerald));
  color: #fff;
  box-shadow: var(--shadow-md);
  padding-top: env(safe-area-inset-top);
}
.app-header__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand__mark {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.16);
  color: var(--gold-soft);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25);
}
[data-theme="dark"] .brand__mark { color: #ffe7a0; }
.brand__name {
  font-size: 1.18rem;
  font-weight: 800;
  letter-spacing: 0.2px;
}
.app-header__actions { display: flex; gap: 8px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 12px;
  border: 0;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  cursor: pointer;
  transition: background .18s ease, transform .12s ease;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.28); }
.icon-btn:active { transform: scale(0.94); }

.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* ---------------- Main ---------------- */
.app-main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 18px 16px 40px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

/* ---------------- Summary ---------------- */
.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.summary__card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.summary__label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  font-weight: 700;
}
.summary__value {
  font-size: 1.12rem;
  font-weight: 800;
  color: var(--text);
  overflow-wrap: anywhere;
}
.summary__card:nth-child(2) .summary__value { color: var(--emerald); }

/* ---------------- Toolbar ---------------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 18px;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform .12s ease, background .18s ease, box-shadow .18s ease, border-color .18s ease;
  line-height: 1;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn--primary {
  background: linear-gradient(120deg, var(--emerald-600), var(--emerald));
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn--primary:hover { box-shadow: 0 6px 16px rgba(5, 150, 105, 0.35); }
.btn--ghost {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}
.btn--ghost:hover { background: var(--surface-3); }
.btn--danger {
  background: var(--danger);
  color: #fff;
}
.btn--danger:hover { filter: brightness(1.05); }
.btn--gold {
  background: linear-gradient(120deg, var(--gold-deep), var(--gold));
  color: #2a2103;
}
[data-theme="dark"] .btn--gold { color: #1a1400; }

.btn--sm { padding: 8px 12px; font-size: 0.85rem; }
.btn--full { width: 100%; }

/* ---------------- Goal cards ---------------- */
.goal-list {
  display: grid;
  gap: 14px;
}
.goal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: box-shadow .2s ease, transform .12s ease;
}
.goal-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: linear-gradient(180deg, var(--emerald-400), var(--emerald-600));
}
.goal-card.is-complete::before {
  background: linear-gradient(180deg, var(--gold), var(--gold-deep));
}
.goal-card:hover { box-shadow: var(--shadow-md); }

.goal-card__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.goal-card__titles { min-width: 0; }
.goal-card__name {
  margin: 0 0 3px;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text);
  overflow-wrap: anywhere;
}
.goal-card__sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.badge--ontrack { background: rgba(5,150,105,0.14); color: var(--emerald-600); }
.badge--behind { background: rgba(217,119,6,0.16); color: var(--warn); }
.badge--done {
  background: linear-gradient(120deg, var(--gold-soft), var(--gold));
  color: #3a2c00;
}
[data-theme="dark"] .badge--ontrack { color: var(--emerald-300); }
[data-theme="dark"] .badge--done { color: #2a2000; }

.goal-card__menu { display: flex; gap: 6px; flex-shrink: 0; }
.mini-btn {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-soft);
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.mini-btn:hover { background: var(--surface-3); color: var(--text); }
.mini-btn--danger:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-bg); }

/* Progress */
.goal-card__amounts {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.goal-card__saved {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--emerald);
}
.goal-card.is-complete .goal-card__saved { color: var(--gold-deep); }
[data-theme="dark"] .goal-card.is-complete .goal-card__saved { color: var(--gold-deep); }
.goal-card__target {
  font-size: 0.92rem;
  color: var(--text-muted);
  font-weight: 600;
}

.progress {
  height: 14px;
  background: var(--track);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
  margin-bottom: 6px;
}
.progress__bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--emerald-400), var(--emerald-600));
  transition: width .5s cubic-bezier(.22,.61,.36,1);
  position: relative;
}
.goal-card.is-complete .progress__bar {
  background: linear-gradient(90deg, var(--gold), var(--gold-deep));
}
.progress__bar::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.35), transparent);
  opacity: .5;
}

.goal-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 0.8rem;
  color: var(--text-soft);
  margin-bottom: 14px;
}
.goal-card__meta strong { color: var(--text); font-weight: 700; }
.goal-card__pct { font-weight: 800; color: var(--emerald); }
.goal-card.is-complete .goal-card__pct { color: var(--gold-deep); }

.goal-card__plan {
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.83rem;
  color: var(--text-soft);
  margin-bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
}
.goal-card__plan strong { color: var(--text); }
.goal-card__plan .rate { color: var(--emerald); font-weight: 800; }

.goal-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.goal-card__actions .btn { flex: 1 1 auto; min-width: 130px; }

/* ---------------- Empty state ---------------- */
.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-soft);
}
.empty-state__icon {
  color: var(--emerald-400);
  margin-bottom: 12px;
}
.empty-state__title { margin: 0 0 6px; font-size: 1.25rem; color: var(--text); }
.empty-state__text { margin: 0 auto 20px; max-width: 360px; }

/* ---------------- Footer ---------------- */
.app-footer {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

/* ---------------- Modals ---------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 30, 22, 0.55);
  backdrop-filter: blur(2px);
  animation: fade .2s ease;
}
.modal__panel {
  position: relative;
  width: 100%;
  max-width: 460px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 20px;
  animation: pop .22s cubic-bezier(.22,.61,.36,1);
}
.modal__panel--wide { max-width: 560px; }
.modal__panel--narrow { max-width: 380px; }
.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}
.modal__head .icon-btn { background: var(--surface-2); color: var(--text-soft); }
.modal__head .icon-btn:hover { background: var(--surface-3); color: var(--text); }
.modal__title { margin: 0; font-size: 1.2rem; font-weight: 800; }
.modal__msg { margin: 0 0 18px; color: var(--text-soft); }

/* ---------------- Forms ---------------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form__context {
  margin: 0;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  color: var(--text-soft);
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}
.field__hint { color: var(--text-muted); font-weight: 500; font-size: 0.78rem; }
.field__input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field__input::placeholder { color: var(--text-muted); }
.field__input:focus {
  outline: none;
  border-color: var(--emerald);
  box-shadow: var(--focus);
}
.field__input.is-invalid { border-color: var(--danger); }
.field__error {
  color: var(--danger);
  font-size: 0.78rem;
  font-weight: 600;
  min-height: 0;
}
.field__error:empty { display: none; }

.form__actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 4px;
}
.form__actions .btn { flex: 1 1 auto; }

/* ---------------- Detail / History ---------------- */
.detail-body { display: flex; flex-direction: column; gap: 14px; }
.detail-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.detail-stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.detail-stat__label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); font-weight: 700; }
.detail-stat__value { font-size: 1.05rem; font-weight: 800; margin-top: 2px; overflow-wrap: anywhere; }

.history-title {
  font-size: 0.95rem;
  font-weight: 800;
  margin: 4px 0 0;
}
.history {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.history-item__main { min-width: 0; }
.history-item__amount { font-weight: 800; }
.history-item__amount.is-pos { color: var(--emerald); }
.history-item__amount.is-neg { color: var(--danger); }
.history-item__meta { font-size: 0.76rem; color: var(--text-muted); overflow-wrap: anywhere; }
.history-empty { color: var(--text-muted); font-size: 0.88rem; text-align: center; padding: 16px; }

/* ---------------- Toast ---------------- */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--text);
  color: var(--surface);
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn .25s ease;
}
.toast.is-out { animation: toastOut .25s ease forwards; }
.toast--success { background: var(--emerald-600); color: #fff; }
.toast--error { background: var(--danger); color: #fff; }
.toast--gold { background: linear-gradient(120deg, var(--gold-deep), var(--gold)); color: #2a2103; }
.toast__icon { flex-shrink: 0; display: grid; place-items: center; }

/* ---------------- Animations ---------------- */
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(16px); } }

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

:focus-visible {
  outline: none;
  box-shadow: var(--focus);
  border-radius: 8px;
}

/* ---------------- Responsive ---------------- */
@media (max-width: 560px) {
  .summary { grid-template-columns: 1fr; }
  .summary__card {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
  .summary__value { font-size: 1.05rem; }
  .detail-stats { grid-template-columns: 1fr; }
  .goal-card__actions .btn { flex: 1 1 100%; }
}

@media (min-width: 561px) and (max-width: 760px) {
  .goal-list { grid-template-columns: 1fr; }
}
@media (min-width: 761px) {
  .goal-list { grid-template-columns: repeat(2, 1fr); }
}
