/* =========================================================================
   Kontor — Designtokens
   Uebernommen aus Birdie (sparrow-neu/public/styles.css), damit die Seiten
   unter hucho.site wie eine Familie aussehen. Die Datenfarbe ist eine einzige
   Blau-Rampe; Statusfarben stehen nie allein, sondern immer mit Symbol und Wort.
   ========================================================================= */

:root {
  color-scheme: light;

  --plane:        #f9f9f7;
  --surface:      #fcfcfb;
  --surface-2:    #f2f1ed;
  --surface-sunk: #eeede8;

  --ink:          #0b0b0b;
  --ink-2:        #52514e;
  --ink-muted:    #898781;

  --line:         #e1e0d9;
  --line-strong:  #c3c2b7;
  --ring:         rgba(11, 11, 11, 0.10);

  --accent:       #2a78d6;
  --accent-hover: #256abf;
  --accent-sunk:  #1c5cab;
  --accent-wash:  #eaf2fd;
  --on-accent:    #ffffff;

  --meter-fill:   #2a78d6;
  --meter-track:  #cde2fb;

  --good:         #0ca30c;
  --good-ink:     #006300;
  --good-wash:    #e8f6e8;
  --warning:      #fab219;
  --warning-ink:  #8a5a00;
  --warning-wash: #fdf3de;
  --critical:     #d03b3b;
  --critical-ink: #a82525;
  --critical-wash:#fbeaea;

  --shadow-sm: 0 1px 2px rgba(11, 11, 11, 0.06);
  --shadow-md: 0 4px 16px rgba(11, 11, 11, 0.08);
  --shadow-lg: 0 12px 40px rgba(11, 11, 11, 0.14);

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

  --topbar-h: 56px;
  --navbar-h: 60px;

  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;

  --ease: cubic-bezier(0.2, 0, 0.15, 1);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;

    --plane:        #0d0d0d;
    --surface:      #1a1a19;
    --surface-2:    #232322;
    --surface-sunk: #121211;

    --ink:          #ffffff;
    --ink-2:        #c3c2b7;
    --ink-muted:    #898781;

    --line:         #2c2c2a;
    --line-strong:  #383835;
    --ring:         rgba(255, 255, 255, 0.10);

    --accent:       #3987e5;
    --accent-hover: #5598e7;
    --accent-sunk:  #6da7ec;
    --accent-wash:  #14243a;
    --on-accent:    #08131f;

    --meter-fill:   #3987e5;
    --meter-track:  #184f95;

    --good-ink:     #0ca30c;
    --good-wash:    #10240f;
    --warning-ink:  #fab219;
    --warning-wash: #2a2008;
    --critical-ink: #e66767;
    --critical-wash:#2c1414;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.55);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.7);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --plane:        #0d0d0d;
  --surface:      #1a1a19;
  --surface-2:    #232322;
  --surface-sunk: #121211;
  --ink:          #ffffff;
  --ink-2:        #c3c2b7;
  --ink-muted:    #898781;
  --line:         #2c2c2a;
  --line-strong:  #383835;
  --ring:         rgba(255, 255, 255, 0.10);
  --accent:       #3987e5;
  --accent-hover: #5598e7;
  --accent-sunk:  #6da7ec;
  --accent-wash:  #14243a;
  --on-accent:    #08131f;
  --meter-fill:   #3987e5;
  --meter-track:  #184f95;
  --good-ink:     #0ca30c;
  --good-wash:    #10240f;
  --warning-ink:  #fab219;
  --warning-wash: #2a2008;
  --critical-ink: #e66767;
  --critical-wash:#2c1414;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.55);
}

/* --- Grundlagen ---------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  /* Safe-Area fuer das iPhone: die untere Navigation darf nicht unter dem
     Home-Indikator liegen. */
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }
p { margin: 0 0 0.6em; }
a { color: var(--accent); }

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Zahlen immer tabellarisch: sonst springen Betragsspalten beim Aktualisieren. */
.num, .amount, .table td, .tile__value, .bar__label {
  font-variant-numeric: tabular-nums;
}

/* --- Gerüst -------------------------------------------------------------- */

.app { display: none; min-height: 100vh; flex-direction: column; }
.app.is-ready { display: flex; }

/* Reihenfolge statt DOM-Umbau: auf dem Handy liegt die Navigation unten, am
   Rechner direkt unter dem Kopf. Das Markup bleibt in beiden Faellen gleich. */
.topbar { order: 0; }
.view { order: 1; }
.nav { order: 2; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  height: var(--topbar-h);
  padding: 0 0.9rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 0.45rem; font-weight: 700; letter-spacing: -0.02em; }
.brand__mark { width: 22px; height: 22px; fill: var(--accent); }
.brand__word { font-size: 1.05rem; }

.topbar__spacer { flex: 1; }

.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  background: transparent;
  color: var(--ink-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 1.05rem;
  cursor: pointer;
}
.iconbtn:hover { background: var(--surface-2); color: var(--ink); }

.view { flex: 1; width: 100%; max-width: 860px; margin: 0 auto; padding: 1rem 0.9rem 1.4rem; }

/* Untere Navigation auf dem Handy, obere Reiter am Rechner. Die Erfassung ist
   der haeufigste Griff und liegt deshalb mittig unter dem Daumen. */
.nav {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav__link {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--navbar-h);
  padding: 0.35rem 0.2rem;
  background: transparent;
  border: 0;
  border-top: 2px solid transparent;
  color: var(--ink-muted);
  font: inherit;
  font-size: 0.7rem;
  text-decoration: none;
  cursor: pointer;
}
.nav__link svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav__link.is-active { color: var(--accent); border-top-color: var(--accent); }
.nav__badge {
  position: absolute;
  transform: translate(14px, -12px);
  min-width: 16px;
  padding: 0 4px;
  background: var(--critical);
  color: #fff;
  border-radius: 999px;
  font-size: 0.62rem;
  line-height: 16px;
  text-align: center;
}

@media (min-width: 760px) {
  .nav {
    position: static;
    display: flex;
    grid-template-columns: none;
    border-top: 0;
    border-bottom: 1px solid var(--line);
    padding: 0 0.9rem;
    gap: 0.15rem;
  }
  .nav__link {
    flex-direction: row;
    gap: 0.4rem;
    min-height: 42px;
    padding: 0 0.7rem;
    border-top: 0;
    border-bottom: 2px solid transparent;
    font-size: 0.88rem;
  }
  .nav__link.is-active { border-bottom-color: var(--accent); }
  .nav__badge { transform: translate(4px, -8px); }
  /* Am Rechner steht die Navigation zwischen Kopf und Inhalt. */
  .nav { order: 1; }
  .view { order: 2; }
}

/* --- Karten und Abschnitte ---------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 0.9rem;
}
.card + .card { margin-top: 0.8rem; }
.card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.7rem;
}
.card__hint { color: var(--ink-muted); font-size: 0.82rem; }

.section { margin-bottom: 1.1rem; }
.section__title { display: flex; align-items: baseline; justify-content: space-between; gap: 0.6rem; margin-bottom: 0.5rem; }

.muted { color: var(--ink-muted); }
.small { font-size: 0.82rem; }
.row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.stack > * + * { margin-top: 0.55rem; }

.empty {
  padding: 1.6rem 1rem;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--ink-muted);
  text-align: center;
}

/* --- Kacheln ------------------------------------------------------------ */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.6rem; }

.tile {
  padding: 0.7rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.tile__label { color: var(--ink-muted); font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em; }
.tile__value { margin-top: 0.15rem; font-size: 1.4rem; font-weight: 650; letter-spacing: -0.02em; }
.tile__note { color: var(--ink-2); font-size: 0.8rem; }
.tile--accent { background: var(--accent-wash); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.tile--good { background: var(--good-wash); }
.tile--warning { background: var(--warning-wash); }
.tile--critical { background: var(--critical-wash); }

/* --- Balken und Ampel --------------------------------------------------- */

.budget { padding: 0.7rem 0; border-bottom: 1px solid var(--line); }
.budget:last-child { border-bottom: 0; }
.budget__head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.6rem; }
.budget__name { font-weight: 600; }
.budget__figures { color: var(--ink-2); font-size: 0.86rem; white-space: nowrap; }

.bar {
  position: relative;
  height: 9px;
  margin: 0.4rem 0 0.3rem;
  background: var(--meter-track);
  border-radius: 999px;
  overflow: hidden;
}
.bar__fill { height: 100%; background: var(--meter-fill); border-radius: 999px; transition: width 0.25s var(--ease); }
.bar__fill--good { background: var(--good); }
.bar__fill--warning { background: var(--warning); }
.bar__fill--critical { background: var(--critical); }
/* Marke fuer das zeitproportionale Soll: zeigt, wo man am heutigen Tag stehen
   sollte. Ohne sie sagt ein halbvoller Balken nichts. */
.bar__pace { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); opacity: 0.45; }

.budget__week { display: flex; align-items: center; gap: 0.5rem; color: var(--ink-2); font-size: 0.8rem; }
.budget__week .bar { flex: 1; height: 5px; margin: 0; }

.light { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.8rem; font-weight: 600; }
.light::before { content: ""; width: 8px; height: 8px; border-radius: 999px; background: currentColor; }
.light--good { color: var(--good-ink); }
.light--warning { color: var(--warning-ink); }
.light--critical { color: var(--critical-ink); }
.light--neutral { color: var(--ink-muted); }

/* --- Schaltflächen ------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 40px;
  padding: 0 0.9rem;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.12s var(--ease);
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn--primary:hover { background: var(--accent-hover); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn--ghost:hover { background: var(--accent-wash); }
.btn--danger { color: var(--critical-ink); border-color: color-mix(in srgb, var(--critical) 40%, transparent); }
.btn--danger:hover { background: var(--critical-wash); }
.btn--block { width: 100%; }
.btn--lg { min-height: 52px; font-size: 1.05rem; }
.btn--sm { min-height: 32px; padding: 0 0.6rem; font-size: 0.84rem; }

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

.field { display: block; margin-bottom: 0.7rem; }
.field__label { display: block; margin-bottom: 0.25rem; color: var(--ink-2); font-size: 0.84rem; font-weight: 550; }
.field__hint { margin-top: 0.2rem; color: var(--ink-muted); font-size: 0.78rem; }
.field__error { margin-top: 0.2rem; color: var(--critical-ink); font-size: 0.82rem; }

.input, .select, .textarea {
  width: 100%;
  min-height: 42px;
  padding: 0.45rem 0.6rem;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  /* 16px verhindert, dass iOS beim Fokus in ein Feld hineinzoomt. */
  font-size: 16px;
}
.input:focus, .select:focus, .textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.textarea { min-height: 72px; resize: vertical; }

.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 0.7rem; }

/* Betragsfeld der Erfassung: gross, damit man beim Gehen nicht danebentippt. */
.amountfield { display: flex; align-items: center; gap: 0.5rem; }
.amountfield__sign { min-width: 52px; }
.amountfield__input {
  flex: 1;
  min-height: 64px;
  font-size: 2rem;
  font-weight: 650;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.amountfield__currency { color: var(--ink-muted); font-size: 1.3rem; }

/* --- Chips -------------------------------------------------------------- */

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-height: 38px;
  padding: 0 0.7rem;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 999px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.chip:hover { border-color: var(--line-strong); }
.chip.is-active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.chip--kind-fix { border-style: dashed; }

/* --- Listen und Tabellen ------------------------------------------------ */

.txlist { display: flex; flex-direction: column; }
.txrow {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.1rem 0.6rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--line);
}
.txrow:last-child { border-bottom: 0; }
.txrow__main { min-width: 0; font-weight: 550; overflow-wrap: anywhere; }
.txrow__amount { font-weight: 650; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.txrow__amount--in { color: var(--good-ink); }
.txrow__meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; color: var(--ink-muted); font-size: 0.8rem; }
.txrow__purpose { grid-column: 1 / -1; color: var(--ink-2); font-size: 0.82rem; overflow-wrap: anywhere; }
.txrow__actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.3rem; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.05rem 0.4rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 0.74rem;
  font-weight: 550;
}
.badge--none { color: var(--critical-ink); background: var(--critical-wash); border-color: transparent; }
.badge--bank { color: var(--ink-muted); }

/* Tabellen scrollen in ihrem eigenen Kasten, die Seite selbst nie. */
.tablewrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { padding: 0.45rem 0.5rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { color: var(--ink-muted); font-size: 0.76rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.table td.right, .table th.right { text-align: right; }
.table tbody tr:last-child td { border-bottom: 0; }

/* --- Meldungen ---------------------------------------------------------- */

.notice {
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  border: 1px solid transparent;
}
.notice + .notice { margin-top: 0.4rem; }
.notice--info { background: var(--accent-wash); color: var(--ink); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.notice--good { background: var(--good-wash); color: var(--good-ink); }
.notice--warn { background: var(--warning-wash); color: var(--warning-ink); }
.notice--error { background: var(--critical-wash); color: var(--critical-ink); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--navbar-h) + 1rem + env(safe-area-inset-bottom));
  z-index: 40;
  transform: translateX(-50%);
  max-width: min(92vw, 460px);
  padding: 0.6rem 0.9rem;
  background: var(--ink);
  color: var(--plane);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
}
.toast--error { background: var(--critical); color: #fff; }
@media (min-width: 760px) { .toast { bottom: 1.2rem; } }

/* --- Anmeldung ---------------------------------------------------------- */

.gate { display: grid; place-items: center; min-height: 100vh; padding: 1.2rem; }
.gate__panel { width: 100%; max-width: 360px; }
.gate__head { margin-bottom: 1rem; text-align: center; }
.gate__head .brand { justify-content: center; margin-bottom: 0.4rem; }

/* --- Sparziele ---------------------------------------------------------- */

.goal { display: flex; align-items: center; gap: 0.8rem; padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.goal:last-child { border-bottom: 0; }
.goal__ring { width: 44px; height: 44px; flex: 0 0 auto; transform: rotate(-90deg); }
.goal__ring circle { fill: none; stroke-width: 5; }
.goal__body { flex: 1; min-width: 0; }
.goal__name { font-weight: 600; }

/* --- Import ------------------------------------------------------------- */

.drop {
  display: grid;
  place-items: center;
  gap: 0.4rem;
  padding: 1.6rem 1rem;
  background: var(--surface-sunk);
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
}
.drop.is-over { border-color: var(--accent); background: var(--accent-wash); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.2rem 0.7rem; font-size: 0.86rem; }
.kv dt { color: var(--ink-muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

.mono { font-family: var(--mono); font-size: 0.82rem; }
