/* ==========================================================================
   Kassensturz – Haushaltsbuch
   Mobile-first, Light/Dark über prefers-color-scheme
   ========================================================================== */

:root {
  /* Farbpalette (Light) */
  --bg: #f4f6f2;
  --surface: #ffffff;
  --surface-2: #eaefe8;
  --border: #d8ded4;
  --ink: #1c2a24;
  --ink-2: #48584f;
  --ink-3: #6f7f75;
  --brand: #0e6e54;
  --brand-strong: #0a523f;
  --brand-soft: #d9ece5;
  --brand-contrast: #ffffff;
  --accent: #b25e12;
  --pos: #1e7a4f;
  --neg: #bc4a3c;
  --warn: #b07d0a;
  --shadow: 0 1px 3px rgba(28, 42, 36, 0.08), 0 4px 16px rgba(28, 42, 36, 0.06);
  --radius: 14px;
  --radius-small: 8px;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Sora", "Inter", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101613;
    --surface: #1a231e;
    --surface-2: #222d27;
    --border: #33403a;
    --ink: #e6ece7;
    --ink-2: #aebbb2;
    --ink-3: #7f8d84;
    --brand: #45b98e;
    --brand-strong: #63cba3;
    --brand-soft: #1d3a30;
    --brand-contrast: #0c1511;
    --accent: #d8925a;
    --pos: #57bd8c;
    --neg: #e07b6c;
    --warn: #d3a83e;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 4px 18px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
}

h1, h2, h3 {
  font-family: var(--font-display);
  line-height: 1.25;
  margin: 0 0 0.35rem;
}
h2 { font-size: 1.1rem; }

button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }

/* ---------- Header ---------- */

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem 0;
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  max-width: 860px;
  margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.brand-mark { width: 38px; height: 38px; flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
}
.brand-claim {
  font-size: 0.72rem;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  max-width: 860px;
  margin: 0.4rem auto 0;
  padding-bottom: 0.5rem;
}
.month-btn {
  width: 40px; height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface-2);
  font-size: 1.15rem;
  line-height: 1;
}
.month-btn:hover { background: var(--brand-soft); }
.month-current {
  border: none;
  background: none;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  min-width: 11rem;
  padding: 0.3rem 0.6rem;
}
.month-current:hover { color: var(--brand); }

/* ---------- Tabs ---------- */

.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  padding: 0.55rem 0.25rem 0.5rem;
  border: none;
  background: none;
  color: var(--ink-3);
  font-size: 0.72rem;
  font-weight: 500;
}
.tab-icon { font-size: 1.15rem; line-height: 1; }
.tab.is-active { color: var(--brand); }
.tab.is-active .tab-icon { transform: translateY(-1px); }

/* ---------- Layout ---------- */

.app-main {
  max-width: 860px;
  margin: 0 auto;
  padding: 1rem 1rem 6.5rem;
}

.view[hidden] { display: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 1rem;
}
.card-sub { margin: 0 0 0.75rem; font-size: 0.82rem; color: var(--ink-3); }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.card-head h2 { margin: 0; }

.privacy-note {
  background: var(--brand-soft);
  border: 1px solid var(--brand);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  font-size: 0.85rem;
  margin: 0 0 1rem;
}

.empty-hint { color: var(--ink-3); font-size: 0.85rem; text-align: center; padding: 0.75rem 0; }

.pill {
  font-size: 0.72rem;
  color: var(--ink-2);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  white-space: nowrap;
}

/* ---------- Summary ---------- */

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.summary-label { font-size: 0.72rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.06em; }
.summary-value { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; }
.summary-value.is-pos { color: var(--pos); }
.summary-value.is-neg { color: var(--neg); }

/* ---------- Charts ---------- */

.chart-wrap { position: relative; width: 100%; }
.chart-wrap canvas { display: block; width: 100%; height: auto; touch-action: pan-y; }

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.78rem;
  padding: 0.3rem 0.55rem;
  border-radius: var(--radius-small);
  white-space: nowrap;
  transform: translate(-50%, -120%);
  z-index: 5;
}

.chart-legend {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  font-size: 0.8rem;
  color: var(--ink-2);
}
.chart-legend li { display: flex; align-items: center; gap: 0.4rem; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* ---------- 50/30/20 ---------- */

.rule-block { margin-bottom: 0.9rem; }
.rule-title {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--ink-2);
  margin-bottom: 0.3rem;
}
.rule-bar {
  display: flex;
  height: 26px;
  border-radius: var(--radius-small);
  overflow: hidden;
  background: var(--surface-2);
  gap: 2px;
}
.rule-seg {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}
.rule-needs { background: var(--brand); }
.rule-wants { background: var(--accent); }
.rule-savings { background: var(--pos); }
.rule-legend { font-size: 0.78rem; color: var(--ink-3); margin: 0.5rem 0 0; }

/* ---------- Formulare ---------- */

.field { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 0.75rem; flex: 1; }
.field-label { font-size: 0.78rem; font-weight: 600; color: var(--ink-2); }
.field-hint { font-size: 0.72rem; color: var(--ink-3); }
.field-row { display: flex; gap: 0.75rem; }

input[type="text"], input[type="date"], input[type="search"],
input[type="number"], select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  padding: 0.6rem 0.7rem;
  width: 100%;
  min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

input[type="color"] {
  width: 100%; height: 2.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface-2);
  padding: 0.2rem;
}

.field-amount input {
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 700;
  text-align: right;
  letter-spacing: 0.02em;
}

.type-toggle {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border-radius: var(--radius-small);
  padding: 3px;
  margin-bottom: 0.9rem;
}
.type-btn {
  flex: 1;
  border: none;
  background: none;
  border-radius: 6px;
  padding: 0.5rem;
  font-weight: 600;
  color: var(--ink-3);
}
.type-btn.is-active[data-type="out"] { background: var(--neg); color: #fff; }
.type-btn.is-active[data-type="in"] { background: var(--pos); color: #fff; }

/* ---------- Buttons ---------- */

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-small);
  padding: 0.6rem 1rem;
  font-weight: 600;
}
.btn:hover { background: var(--brand-soft); }
.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-contrast);
}
.btn-primary:hover { background: var(--brand-strong); }
.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: var(--brand);
}
.btn-ghost {
  background: none;
  border-color: var(--brand);
  color: var(--brand);
  font-size: 0.8rem;
  padding: 0.4rem 0.7rem;
  white-space: nowrap;
}
.btn-ghost:hover { background: var(--brand-soft); }
.btn-small { font-size: 0.8rem; padding: 0.35rem 0.7rem; }
.btn-block { width: 100%; }
.btn-danger { border-color: var(--neg); color: var(--neg); background: none; }
.btn-danger:hover { background: var(--neg); color: #fff; }
.btn-stack { display: flex; flex-direction: column; gap: 0.5rem; }

.icon-btn {
  border: none;
  background: none;
  color: var(--ink-3);
  font-size: 0.95rem;
  padding: 0.3rem 0.4rem;
  border-radius: var(--radius-small);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ---------- Buchungsliste ---------- */

.filter-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; }
.filter-row input[type="search"] { flex: 2 1 160px; }
.filter-row select { flex: 1 1 120px; width: auto; }

.tx-list, .budget-list, .cat-list, .rec-list { list-style: none; margin: 0; padding: 0; }

.tx-day-head {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-3);
  padding: 0.7rem 0 0.25rem;
  border-bottom: 1px solid var(--border);
}
.tx-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
}
.tx-emoji {
  width: 36px; height: 36px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font-size: 1.05rem;
}
.tx-main { flex: 1; min-width: 0; }
.tx-title { font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-meta { font-size: 0.75rem; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-amount { font-family: var(--font-display); font-weight: 700; font-size: 0.95rem; white-space: nowrap; }
.tx-amount.is-pos { color: var(--pos); }
.tx-amount.is-neg { color: var(--neg); }
.tx-actions { display: flex; flex: none; }
.tx-badge {
  font-size: 0.62rem;
  background: var(--surface-2);
  color: var(--ink-3);
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  margin-left: 0.35rem;
  vertical-align: middle;
}

/* ---------- Budgets ---------- */

.budget-item { padding: 0.7rem 0; border-bottom: 1px solid var(--border); }
.budget-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.budget-name { flex: 1; font-weight: 600; font-size: 0.9rem; min-width: 0; }
.budget-input {
  width: 7.5rem !important;
  text-align: right;
  padding: 0.35rem 0.5rem !important;
}
.budget-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.budget-fill { height: 100%; border-radius: 999px; transition: width 0.25s ease; }
.budget-fill.ok { background: var(--pos); }
.budget-fill.warn { background: var(--warn); }
.budget-fill.over { background: var(--neg); }
.budget-meta { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--ink-3); margin-top: 0.3rem; }

/* ---------- Kategorien & Wiederkehrend ---------- */

.cat-item, .rec-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
}
.cat-swatch {
  width: 34px; height: 34px;
  flex: none;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}
.cat-main { flex: 1; min-width: 0; }
.cat-name { font-weight: 600; font-size: 0.9rem; }
.cat-meta { font-size: 0.73rem; color: var(--ink-3); }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 0.35rem;
}
.emoji-option {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-small);
  font-size: 1.2rem;
  padding: 0.35rem 0;
}
.emoji-option.is-selected {
  border-color: var(--brand);
  background: var(--brand-soft);
  outline: 2px solid var(--brand);
}

/* ---------- Ad-Slot ---------- */

.ad-slot {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0.9rem;
  text-align: center;
  margin-bottom: 1rem;
}
.ad-slot-label {
  display: block;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-3);
  margin-bottom: 0.3rem;
}
.ad-slot-placeholder { margin: 0; font-size: 0.8rem; color: var(--ink-3); }

/* ---------- Footer ---------- */

.app-footer {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 1rem 6rem;
  text-align: center;
  font-size: 0.78rem;
  color: var(--ink-3);
}
.app-footer p { margin: 0.25rem 0; }
.link-btn {
  border: none;
  background: none;
  color: var(--brand);
  text-decoration: underline;
  padding: 0;
  font-size: inherit;
}

/* ---------- Modals ---------- */

.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  width: min(92vw, 460px);
  max-height: 85vh;
  overflow-y: auto;
}
.modal::backdrop { background: rgba(10, 18, 14, 0.55); }
.modal-close-form { float: right; margin: -0.4rem -0.4rem 0 0; }
.modal-close {
  border: none;
  background: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--ink-3);
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-small);
}
.modal-close:hover { background: var(--surface-2); color: var(--ink); }
.modal-note { font-size: 0.8rem; color: var(--ink-3); }
.feature-list { padding-left: 1.2rem; margin: 0.5rem 0 0.75rem; }
.feature-list li { margin-bottom: 0.25rem; }

/* ---------- Erste-Schritte-Hilfe ---------- */

.header-actions { display: flex; align-items: center; gap: 0.5rem; }
.help-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
}
.help-steps { margin: 0.5rem 0 0.75rem; padding-left: 1.3rem; }
.help-steps li { margin-bottom: 0.5rem; }
.help-subtitle { margin: 0.75rem 0 0.25rem; font-size: 0.9rem; }
.help-know {
  margin: 0 0 0.25rem;
  padding-left: 1.2rem;
  font-size: 0.85rem;
  color: var(--ink-2);
}
.help-know li { margin-bottom: 0.3rem; }
.modal-actions { margin: 0.75rem 0 0; }

/* ---------- Desktop ---------- */

@media (min-width: 700px) {
  .tabbar {
    position: sticky;
    top: auto;
    bottom: auto;
    border-top: none;
    border-bottom: 1px solid var(--border);
    justify-content: center;
    gap: 0.5rem;
    padding: 0 1rem;
  }
  .tab {
    flex: none;
    flex-direction: row;
    gap: 0.4rem;
    font-size: 0.88rem;
    padding: 0.7rem 1rem;
    border-bottom: 2px solid transparent;
  }
  .tab.is-active { border-bottom-color: var(--brand); }
  .app-main { padding-bottom: 2rem; }
  .app-footer { padding-bottom: 2rem; }
  .summary-grid { grid-template-columns: repeat(4, 1fr); }
}
