/* ============================================================
   Ausgaben-Dashboard – Design System
   ============================================================ */

:root {
  color-scheme: light;

  --bg:        #f6f5f2;
  --bg-grad:   radial-gradient(1200px 600px at 15% -10%, #ffffff 0%, #f6f5f2 55%);
  --surface:   #ffffff;
  --surface-2: #faf9f7;
  --surface-3: #f0efec;
  --border:    #e4e1db;
  --border-2:  #d5d1c9;

  --text:      #1c1b19;
  --text-dim:  #6d6a63;
  --text-mute: #97938b;

  --accent:      #4f46e5;
  --accent-soft: #eceafd;

  --exp:       #d1453b;
  --exp-soft:  #fdeceb;
  --inc:       #15803d;
  --inc-soft:  #e7f6ec;
  --warn:      #b45309;
  --warn-soft: #fdf1e0;

  --shadow-s: 0 1px 2px rgba(28,27,25,.05);
  --shadow-m: 0 2px 4px rgba(28,27,25,.04), 0 8px 24px rgba(28,27,25,.06);
  --shadow-l: 0 8px 40px rgba(28,27,25,.14);

  --r-s: 8px;
  --r-m: 12px;
  --r-l: 18px;
  --r-full: 999px;

  --nav-h: 62px;
  --maxw: 1180px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:        #131316;
    --bg-grad:   radial-gradient(1200px 600px at 15% -10%, #1e1e24 0%, #131316 55%);
    --surface:   #1b1b20;
    --surface-2: #202027;
    --surface-3: #292930;
    --border:    #2e2e37;
    --border-2:  #3d3d48;

    --text:      #eceaf3;
    --text-dim:  #a3a0ad;
    --text-mute: #74717e;

    --accent:      #7c74ff;
    --accent-soft: #26243d;

    --exp:       #ff6b60;
    --exp-soft:  #33201f;
    --inc:       #4ade80;
    --inc-soft:  #16291d;
    --warn:      #fbbf24;
    --warn-soft: #2e2413;

    --shadow-s: 0 1px 2px rgba(0,0,0,.4);
    --shadow-m: 0 2px 4px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
    --shadow-l: 0 8px 40px rgba(0,0,0,.55);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:        #131316;
  --bg-grad:   radial-gradient(1200px 600px at 15% -10%, #1e1e24 0%, #131316 55%);
  --surface:   #1b1b20;
  --surface-2: #202027;
  --surface-3: #292930;
  --border:    #2e2e37;
  --border-2:  #3d3d48;

  --text:      #eceaf3;
  --text-dim:  #a3a0ad;
  --text-mute: #74717e;

  --accent:      #7c74ff;
  --accent-soft: #26243d;

  --exp:       #ff6b60;
  --exp-soft:  #33201f;
  --inc:       #4ade80;
  --inc-soft:  #16291d;
  --warn:      #fbbf24;
  --warn-soft: #2e2413;

  --shadow-s: 0 1px 2px rgba(0,0,0,.4);
  --shadow-m: 0 2px 4px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  --shadow-l: 0 8px 40px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4 { margin: 0; font-weight: 620; letter-spacing: -.015em; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

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

.app { min-height: 100%; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px); }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 16px; }

/* ---------- Topbar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 10px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -.02em; font-size: 15px; }
.brand-dot {
  width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #ff8a5b));
  color: #fff; font-size: 14px; box-shadow: var(--shadow-s);
}
.brand small { display: block; font-weight: 500; font-size: 10.5px; color: var(--text-mute); letter-spacing: .06em; text-transform: uppercase; }

.spacer { flex: 1 1 auto; }

.monthnav {
  display: flex; align-items: center; gap: 2px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-full); padding: 3px; box-shadow: var(--shadow-s);
}
.monthnav button {
  width: 30px; height: 30px; border: 0; border-radius: 50%; background: transparent;
  color: var(--text-dim); display: grid; place-items: center; font-size: 15px;
}
.monthnav button:hover { background: var(--surface-3); color: var(--text); }
.monthnav .label {
  min-width: 116px; text-align: center; font-weight: 600; font-size: 13.5px;
  padding: 4px 6px; letter-spacing: -.01em; user-select: none; border: 0; background: none;
  border-radius: var(--r-full); cursor: pointer;
}
.monthnav .label:hover { background: var(--surface-3); }

.icon-btn {
  width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-dim); display: grid; place-items: center;
  box-shadow: var(--shadow-s); font-size: 15px; flex: none;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-2); }
.icon-btn svg { width: 17px; height: 17px; }

.sync-pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600;
  padding: 6px 11px; border-radius: var(--r-full); border: 1px solid var(--border);
  background: var(--surface); color: var(--text-dim); white-space: nowrap;
}
.sync-pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-mute); flex: none; }
.sync-pill.cloud i { background: var(--inc); }
.sync-pill.busy i { background: var(--warn); animation: pulse 1s infinite; }
.sync-pill.error i { background: var(--exp); }
@keyframes pulse { 50% { opacity: .25; } }
@media (max-width: 700px) { .sync-pill .txt { display: none; } .sync-pill { padding: 6px; } }

/* Auf schmalen Displays rutscht die Monatsauswahl in eine eigene Zeile */
@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; row-gap: 8px; padding: 9px 14px; }
  .monthnav { order: 5; width: 100%; justify-content: space-between; }
  .monthnav .label { flex: 1 1 auto; min-width: 0; }
  .monthnav button:not(.label) { width: 34px; height: 34px; }
}

/* ---------- Nav ---------- */

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; justify-content: space-around; align-items: stretch;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
.nav button {
  flex: 1 1 0; border: 0; background: none; color: var(--text-mute);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 10px; font-weight: 600; letter-spacing: .01em; padding: 0 2px;
  position: relative; transition: color .15s;
}
.nav button svg { width: 21px; height: 21px; }
.nav button.active { color: var(--accent); }
.nav button.active::before {
  content: ""; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 26px; height: 2.5px; border-radius: 0 0 3px 3px; background: var(--accent);
}

@media (min-width: 860px) {
  .app { padding-bottom: 40px; }
  .nav {
    position: sticky; top: 56px; bottom: auto; height: auto;
    max-width: var(--maxw); margin: 14px auto 0; border: 1px solid var(--border);
    border-radius: var(--r-full); background: var(--surface); box-shadow: var(--shadow-s);
    justify-content: flex-start; gap: 2px; padding: 4px; width: calc(100% - 32px);
    backdrop-filter: none;
  }
  .nav button {
    flex: 0 1 auto; flex-direction: row; gap: 7px; font-size: 13px; padding: 8px 14px;
    border-radius: var(--r-full);
  }
  .nav button svg { width: 16px; height: 16px; }
  .nav button.active { background: var(--accent-soft); color: var(--accent); }
  .nav button.active::before { display: none; }
}

/* ---------- View / sections ---------- */

.view { display: none; padding-top: 18px; animation: fade .22s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.section-head { display: flex; align-items: baseline; gap: 10px; margin: 0 0 12px; flex-wrap: wrap; }
.section-head h2 { font-size: 17px; }
.section-head .hint { font-size: 12.5px; color: var(--text-mute); }

.grid { display: grid; gap: 14px; }
.grid.k2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.k4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 760px) { .grid.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 759px) { .grid.k2 { grid-template-columns: 1fr; } }
.cols { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .cols.side { grid-template-columns: minmax(0,1.3fr) minmax(0,1fr); align-items: start; } }

/* ---------- Card ---------- */

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-l); padding: 16px; box-shadow: var(--shadow-s);
}
.stack > * + * { margin-top: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h3 { font-size: 14px; letter-spacing: -.01em; }
.card-head .sub { font-size: 12px; color: var(--text-mute); font-weight: 500; }

.kpi { padding: 15px 16px 14px; }
.kpi .label {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-mute); display: flex; align-items: center; gap: 6px;
}
.kpi .value { font-size: 25px; font-weight: 600; letter-spacing: -.03em; margin-top: 7px; line-height: 1.1; }
.kpi .foot { font-size: 11.5px; color: var(--text-mute); margin-top: 6px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.kpi.exp .value { color: var(--exp); }
.kpi.inc .value { color: var(--inc); }
.pos { color: var(--inc); }
.neg { color: var(--exp); }

.trend { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: var(--r-full); }
.trend.up { background: var(--exp-soft); color: var(--exp); }
.trend.down { background: var(--inc-soft); color: var(--inc); }
.trend.flat { background: var(--surface-3); color: var(--text-mute); }

/* ---------- Forms ---------- */

.field { display: block; margin-bottom: 13px; }
.field > .lbl {
  display: block; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-mute); margin-bottom: 6px;
}
.input {
  width: 100%; padding: 11px 13px; border-radius: var(--r-m);
  border: 1px solid var(--border-2); background: var(--surface-2); color: var(--text);
  outline: none; transition: border-color .15s, box-shadow .15s, background .15s;
}
.input:focus {
  border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
textarea.input { resize: vertical; min-height: 60px; }
select.input {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-mute) 50%), linear-gradient(135deg, var(--text-mute) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 34px;
}
.row { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
@media (max-width: 560px) { .row.stack-sm { grid-template-columns: 1fr; } }

.amount-field { position: relative; }
.amount-field input {
  font-size: 29px; font-weight: 600; letter-spacing: -.03em; padding: 13px 48px 13px 14px;
  font-variant-numeric: tabular-nums;
}
.amount-field .cur {
  position: absolute; right: 16px; top: 50%; transform: translateY(-50%);
  font-size: 20px; color: var(--text-mute); font-weight: 500; pointer-events: none;
}

.segmented {
  display: grid; grid-auto-flow: column; gap: 3px; padding: 3px;
  background: var(--surface-3); border-radius: var(--r-m); border: 1px solid var(--border);
}
.segmented button {
  border: 0; background: transparent; border-radius: 9px; padding: 9px 10px;
  font-size: 13.5px; font-weight: 600; color: var(--text-dim); transition: all .15s;
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-s); }
.segmented button.active[data-type="expense"] { color: var(--exp); }
.segmented button.active[data-type="income"] { color: var(--inc); }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px 8px 9px;
  border-radius: var(--r-full); border: 1px solid var(--border-2); background: var(--surface-2);
  font-size: 13px; font-weight: 550; color: var(--text-dim); transition: all .13s;
}
.chip:hover { border-color: var(--text-mute); color: var(--text); }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.chip.active { color: var(--text); font-weight: 650; border-color: transparent; box-shadow: inset 0 0 0 1.6px currentColor; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 11px 17px; border-radius: var(--r-m); border: 1px solid var(--border-2);
  background: var(--surface); color: var(--text); font-weight: 600; font-size: 14px;
  transition: all .14s; box-shadow: var(--shadow-s);
}
.btn:hover { border-color: var(--text-mute); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--exp); border-color: color-mix(in srgb, var(--exp) 35%, var(--border)); background: var(--exp-soft); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-dim); }
.btn.ghost:hover { background: var(--surface-3); color: var(--text); }
.btn.wide { width: 100%; }
.btn.sm { padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  width: 54px; height: 54px; border-radius: 50%; border: 0; z-index: 45;
  background: var(--accent); color: #fff; font-size: 28px; line-height: 1;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 45%, transparent);
  display: grid; place-items: center;
}
.fab:active { transform: scale(.94); }
@media (min-width: 860px) { .fab { display: none; } }

/* ---------- Lists ---------- */

.list { display: flex; flex-direction: column; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 11px 6px;
  border-bottom: 1px solid var(--border); cursor: pointer; transition: background .12s;
  border-radius: 8px; text-align: left; background: none; border-left: 0; border-right: 0; border-top: 0;
  width: 100%;
}
.item:last-child { border-bottom: 0; }
.item:hover { background: var(--surface-2); }
.item .ic {
  width: 38px; height: 38px; border-radius: 11px; flex: none; display: grid; place-items: center;
  font-size: 17px;
}
.item .mid { flex: 1 1 auto; min-width: 0; }
.item .t1 { font-weight: 570; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .t2 { font-size: 12px; color: var(--text-mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 6px; align-items: center; }
.item .amt { font-weight: 620; font-size: 14.5px; white-space: nowrap; letter-spacing: -.01em; }

.daygroup { margin-top: 15px; }
.daygroup:first-child { margin-top: 0; }
.dayhead {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-mute); padding: 4px 6px 6px;
}

.empty { text-align: center; padding: 34px 16px; color: var(--text-mute); }
.empty .big { font-size: 30px; margin-bottom: 8px; opacity: .5; }
.empty p { font-size: 13.5px; }

/* ---------- Budget bars ---------- */

.bud { padding: 12px 0; border-bottom: 1px solid var(--border); }
.bud:last-child { border-bottom: 0; }
.bud-top { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.bud-top .nm { flex: 1 1 auto; font-weight: 570; font-size: 13.5px; display: flex; align-items: center; gap: 7px; min-width: 0; }
.bud-top .nm span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bud-top .vals { font-size: 12.5px; color: var(--text-dim); white-space: nowrap; }
.bar { height: 8px; border-radius: var(--r-full); background: var(--surface-3); overflow: hidden; position: relative; }
.bar > i { display: block; height: 100%; border-radius: var(--r-full); transition: width .5s cubic-bezier(.2,.8,.2,1); }
.bud-foot { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-mute); margin-top: 6px; gap: 10px; }

/* ---------- Table ---------- */

.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-mute); font-weight: 700; padding: 8px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 10px 8px; border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: 0; }
.table .r { text-align: right; }
.table-scroll { overflow-x: auto; }

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

.chart-wrap svg { width: 100%; height: auto; display: block; overflow: visible; }
.legend { display: flex; flex-direction: column; gap: 1px; }
.legend-row {
  display: flex; align-items: center; gap: 9px; padding: 6px; border-radius: 8px; font-size: 13px;
}
.legend-row:hover { background: var(--surface-2); }
.legend-row .dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.legend-row .nm { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-row .vl { font-weight: 600; white-space: nowrap; }
.legend-row .pc { color: var(--text-mute); font-size: 12px; width: 44px; text-align: right; }

/* ---------- Modal ---------- */

.modal-back {
  position: fixed; inset: 0; z-index: 100; background: rgba(15,15,20,.5);
  backdrop-filter: blur(3px); display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s;
}
@media (min-width: 620px) { .modal-back { align-items: center; padding: 24px; } }
.modal {
  background: var(--surface); width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
  border-radius: var(--r-l) var(--r-l) 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-l); animation: slideup .24s cubic-bezier(.2,.9,.25,1);
  border: 1px solid var(--border);
}
@media (min-width: 620px) { .modal { border-radius: var(--r-l); padding-bottom: 20px; } }
@keyframes slideup { from { transform: translateY(22px); opacity: .4; } }
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.modal-head h3 { font-size: 17px; flex: 1 1 auto; }

/* ---------- Toast ---------- */

.toasts {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 200;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 18px);
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
  width: max-content; max-width: 92vw;
}
@media (min-width: 860px) { .toasts { bottom: 24px; } }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--r-full);
  font-size: 13.5px; font-weight: 560; box-shadow: var(--shadow-l); animation: slideup .2s;
  text-align: center;
}
.toast.err { background: var(--exp); color: #fff; }
.toast.ok  { background: var(--inc); color: #fff; }

/* ---------- Misc ---------- */

.note {
  font-size: 12.5px; color: var(--text-dim); background: var(--surface-2);
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  padding: 11px 13px; border-radius: var(--r-s); line-height: 1.55;
}
.note.warn { border-left-color: var(--warn); }
.note code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

.tag {
  font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  padding: 3px 6px; border-radius: 5px; background: var(--surface-3); color: var(--text-dim);
}
.tag.rec { background: var(--accent-soft); color: var(--accent); }

.divider { height: 1px; background: var(--border); margin: 16px 0; }

.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 13.5px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  width: 40px; height: 23px; border-radius: var(--r-full); background: var(--surface-3);
  border: 1px solid var(--border-2); position: relative; transition: background .18s, border-color .18s; flex: none;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow-s); transition: transform .18s;
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(17px); background: #fff; }

.gate {
  position: fixed; inset: 0; z-index: 300; background: var(--bg); background-image: var(--bg-grad);
  display: grid; place-items: center; padding: 24px;
}
.gate .box { width: 100%; max-width: 340px; text-align: center; }
.gate .brand-dot { width: 44px; height: 44px; font-size: 22px; margin: 0 auto 14px; border-radius: 13px; }

.hide { display: none !important; }
