/* ===== Haushaltsbuch – responsive: Handy, Tablet, Laptop, Fernseher =====
   Alles in rem: Die Basisgröße (html) wächst mit der Bildschirmbreite, dadurch skaliert das ganze Layout mit. */
:root {
  color-scheme: light;
  --bg: #fff4f6; --card: #fffdfd; --side-bg: #ffe6ec; --text: #4a2c38; --muted: #8f6f7c; --line: #f5dde4; --edge: #f0cdd8;
  --primary: #e0527f; --primary-text: #fff; --pos: #3d9a7b; --neg: #c0355b; --warn: #d98a2c;
  --shadow: 0 .125rem .875rem rgba(224, 82, 127, .08);
  --radius: 1.25rem; --side: 15rem;
  --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --nav-h: 4.25rem;
}
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
@media (min-width: 1700px) { html { font-size: 18px; } }
@media (min-width: 2200px) { html { font-size: 22px; } }
@media (min-width: 3000px) { html { font-size: 28px; } }
@media (min-width: 3800px) { html { font-size: 34px; } }
@media (max-width: 380px) { html { font-size: 15px; } }

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 1rem/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; overflow-x: hidden; }
a { color: var(--primary); }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 1.8rem; font-family: var(--serif); font-weight: 500; line-height: 1.2; }
h2 { font-size: 1.05rem; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); } .pos { color: var(--pos); } .neg { color: var(--neg); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }
.only-phone { display: none; }
:focus-visible { outline: .19rem solid var(--primary); outline-offset: .13rem; border-radius: .5rem; }  /* Tastatur / Fernbedienung */

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.side { background: var(--side-bg); padding: 1.4rem .9rem; position: sticky; top: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; gap: .25rem; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: .65rem; font-family: var(--serif); font-size: 1.3rem; padding: .25rem .75rem 1.4rem; }
.brand i { width: 1.9rem; height: 1.9rem; border-radius: 50%; background: var(--primary); display: grid; place-items: center; color: #fff; font-style: normal; font-family: var(--serif); font-size: 1rem; flex: none; }
.nav { display: grid; gap: .2rem; }
.nav a { display: flex; align-items: center; gap: .7rem; padding: .65rem .95rem; border-radius: 99px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a:hover { background: rgba(255, 255, 255, .6); color: var(--text); }
.nav a.active { background: var(--primary); color: #fff; }
.nav .ic { display: none; width: 1.35rem; height: 1.35rem; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.side .user { margin-top: auto; padding: .8rem; border-radius: 1rem; background: rgba(255, 255, 255, .55); font-size: .9rem; }
.main { padding: 1.75rem clamp(.9rem, 3vw, 2.5rem) 4rem; width: 100%; min-width: 0; max-width: 92rem; margin-inline: auto; }
.grid > *, .hero > * { min-width: 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: .75rem 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.fab { display: none; }

/* ---------- Bausteine ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }
.card h2 { font-family: var(--serif); font-weight: 500; font-size: 1.15rem; margin-bottom: .75rem; display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.grid { display: grid; gap: 1rem; }
.g4 { grid-template-columns: repeat(auto-fit, minmax(min(12rem, 100%), 1fr)); }
.g2 { grid-template-columns: repeat(auto-fit, minmax(min(22rem, 100%), 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(min(16rem, 100%), 1fr)); }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-family: var(--serif); font-size: 1.7rem; font-weight: 500; margin-top: .1rem; }
.btn { border: 1px solid var(--edge); background: var(--card); padding: .5rem 1rem; border-radius: 99px; cursor: pointer; font-weight: 500; min-height: 2.5rem; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; text-decoration: none; color: var(--text); }
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.danger { color: var(--neg); }
.btn.sm { padding: .25rem .7rem; font-size: .85rem; min-height: 2rem; }
.btn.icon { padding: .35rem .7rem; }
.chip { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; padding: .1rem .6rem; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); }
.dot { width: .65rem; height: .65rem; border-radius: 50%; display: inline-block; flex: none; }
.chart-box { position: relative; height: clamp(14rem, 22vw, 20rem); }
.empty { color: var(--muted); text-align: center; padding: 1.75rem .5rem; }

input, select { background: #fff; border: 1px solid var(--edge); border-radius: .75rem; padding: .55rem .75rem; width: 100%; min-height: 2.5rem; }
input[type=color] { padding: .125rem; height: 2.5rem; width: 4rem; }
input[type=checkbox] { min-height: 0; }
label.f { display: grid; gap: .25rem; font-size: .85rem; color: var(--muted); }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .9rem; }
.filters > * { width: auto; min-width: 8rem; flex: 1 1 8rem; }

/* ---------- Tabellen & Listen ---------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--muted); font-weight: 550; font-size: .8rem; padding: .4rem .65rem; border-bottom: 1px solid var(--line); }
td { padding: .65rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.list { display: grid; }
.list .it { display: flex; gap: .75rem; align-items: center; padding: .65rem 0; border-bottom: 1px solid var(--line); }
.list .it:last-child { border-bottom: 0; }
.list .it .grow { flex: 1; min-width: 0; }
.list .it .grow > div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: .5rem; background: var(--bg); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.bar > span { display: block; height: 100%; border-radius: 99px; }
.acct { border-left: .3rem solid var(--c, var(--primary)); }

/* ---------- Startseite ---------- */
.hero { display: grid; grid-template-columns: 1.25fr 1fr; gap: 1rem; margin-bottom: 1.4rem; }
.hero-main { background: var(--primary); color: #fff; border-radius: 1.75rem; padding: 1.75rem 1.9rem; box-shadow: 0 .6rem 1.9rem rgba(224, 82, 127, .28); }
.hero-label { opacity: .85; font-size: .9rem; letter-spacing: .02em; }
.hero-big { font-family: var(--serif); font-size: clamp(2.2rem, 4vw, 3.2rem); line-height: 1.1; margin: .25rem 0 .4rem; }
.hero-sub { opacity: .92; font-size: .92rem; }
.hero-mini { display: flex; gap: .6rem; margin-top: 1.4rem; flex-wrap: wrap; }
.hero-mini > div { background: rgba(255, 255, 255, .2); border-radius: 1rem; padding: .55rem .85rem; flex: 1 1 6rem; display: grid; }
.hero-mini span { font-size: .78rem; opacity: .85; }
.hero-mini strong { font-weight: 600; }
.hero-week { display: flex; flex-direction: column; justify-content: center; }
.hero-week h2 { margin-bottom: .9rem; }
.week-row { display: flex; gap: 1.25rem; align-items: center; }
.ring { --p: 0; --c: var(--primary); width: 7rem; height: 7rem; border-radius: 50%; flex: none; display: grid; place-items: center; background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--side-bg) 0); }
.ring > div { width: 5.25rem; height: 5.25rem; border-radius: 50%; background: var(--card); display: grid; place-content: center; text-align: center; line-height: 1.15; }
.ring strong { font-size: 1.15rem; font-weight: 600; }
.ring span { font-size: .7rem; color: var(--muted); }
.week-big { font-family: var(--serif); font-size: 2rem; line-height: 1.1; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; margin: 0 .15rem .6rem; }
.section-head h2 { font-family: var(--serif); font-weight: 500; font-size: 1.3rem; }
.section-head a { font-size: .88rem; }

/* ---------- Kalender ---------- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .25rem; }
.cal .dow { text-align: center; font-size: .8rem; color: var(--muted); padding: .25rem; }
.cal .day { min-height: 5.25rem; border: 1px solid var(--line); border-radius: .9rem; padding: .3rem .4rem; cursor: pointer; background: var(--card); overflow: hidden; text-align: left; }
.cal .day:hover { border-color: var(--primary); }
.cal .day.out { opacity: .35; pointer-events: none; }
.cal .day.today { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.cal .day.sel { background: color-mix(in srgb, var(--primary) 10%, var(--card)); }
.cal .d { font-size: .8rem; color: var(--muted); }
.cal .e { font-size: .72rem; display: flex; justify-content: space-between; gap: .25rem; margin-top: .125rem; }
.cal .e.future { opacity: .7; font-style: italic; }

/* ---------- Modal, Toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(74, 44, 56, .35); display: grid; place-items: center; padding: 1rem; z-index: 50; }
.modal { background: var(--card); border-radius: 1.6rem; width: min(30rem, 100%); max-height: 92vh; max-height: 92dvh; overflow: auto; padding: 1.6rem; box-shadow: 0 1.25rem 3.75rem rgba(224, 82, 127, .25); }
.modal h2 { font-family: var(--serif); font-weight: 500; font-size: 1.3rem; }
.modal form { display: grid; gap: .75rem; margin-top: .9rem; }
.modal .actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .25rem; flex-wrap: wrap; }
.seg { display: grid; grid-auto-flow: column; gap: .25rem; background: var(--side-bg); padding: .25rem; border-radius: 99px; }
.seg button { border: 0; background: none; padding: .5rem; border-radius: 99px; cursor: pointer; font-weight: 500; color: var(--muted); min-height: 2.25rem; }
.seg button.on { background: var(--primary); color: #fff; }
.err { color: var(--neg); font-size: .9rem; min-height: 1.2em; }
#toast { position: fixed; bottom: 1.1rem; left: 50%; transform: translate(-50%, 1.2rem); background: var(--text); color: var(--bg); padding: .65rem 1.1rem; border-radius: .7rem; opacity: 0; transition: .25s; pointer-events: none; z-index: 99; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Login ---------- */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 1rem; }
.auth .card { width: min(25rem, 100%); padding: 1.75rem; }
.auth form { display: grid; gap: .75rem; margin-top: 1rem; }

/* ================= Tablet hochkant & Handy: Navigation unten ================= */
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; inset: auto 0 0 0; height: auto; flex-direction: row; padding: .35rem .5rem calc(.35rem + var(--safe-b)); z-index: 40; overflow: visible; box-shadow: 0 -.125rem .875rem rgba(224, 82, 127, .14); gap: 0; }
  .brand, .side .user { display: none; }
  .nav { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; gap: .1rem; }
  .nav a { flex-direction: column; gap: .1rem; padding: .35rem .2rem; font-size: .72rem; border-radius: 1rem; justify-content: center; text-align: center; min-height: 3.1rem; }
  .nav .ic { display: block; }
  .main { padding-bottom: calc(var(--nav-h) + 1.5rem + var(--safe-b)); padding-top: 1.1rem; }
  h1 { font-size: 1.6rem; }
  .only-phone { display: block; }
  #add { display: none; }
  .fab { display: grid; place-items: center; position: fixed; right: 1rem; bottom: calc(var(--nav-h) + .9rem + var(--safe-b)); width: 3.5rem; height: 3.5rem; border-radius: 50%; border: 0; background: var(--primary); color: #fff; font-size: 2rem; line-height: 1; cursor: pointer; box-shadow: 0 .5rem 1.25rem rgba(224, 82, 127, .45); z-index: 45; }
  #toast { bottom: calc(var(--nav-h) + 1rem + var(--safe-b)); }
}

/* ================= Handy ================= */
@media (max-width: 600px) {
  .nav a.sec { display: none; }  /* Termine, Kalender, Budgets liegen unter "Mehr" */
  .card { padding: 1rem; border-radius: 1.1rem; }
  .hero { grid-template-columns: 1fr; }
  .top { margin-bottom: .9rem; }
  .top .row { width: 100%; }
  .hero-main { padding: 1.35rem 1.25rem; border-radius: 1.5rem; }
  .hero-sub { font-size: .85rem; }
  .week-row { gap: 1rem; }
  .ring { width: 6rem; height: 6rem; } .ring > div { width: 4.5rem; height: 4.5rem; }
  .week-big { font-size: 1.7rem; }
  .stat .value { font-size: 1.45rem; }
  .chart-box { height: 14.5rem; }
  .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); }
  .filters > * { flex: 1 1 calc(50% - .5rem); min-width: 0; }
  /* Eingaben mind. 16px, sonst zoomt iOS beim Tippen heran */
  input, select { font-size: 16px; }
  /* Modal als Sheet von unten */
  .overlay { align-items: end; padding: 0; }
  .modal { width: 100%; border-radius: 1.6rem 1.6rem 0 0; padding: 1.25rem 1.25rem calc(1.25rem + var(--safe-b)); max-height: 94dvh; }
  /* Buchungstabelle wird zur Liste */
  .rt thead { display: none; }
  .rt, .rt tbody { display: block; }
  .rt tr { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem .6rem; padding: .7rem 0; border-bottom: 1px solid var(--line); }
  .rt tr:last-child { border-bottom: 0; }
  .rt td { border: 0; padding: 0; }
  .rt .c-desc { order: 1; flex: 1 1 55%; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
  .rt .c-amt { order: 2; margin-left: auto; font-weight: 600; }
  .rt .c-date { order: 3; font-size: .82rem; color: var(--muted); }
  .rt .c-cat { order: 4; } .rt .c-acc { order: 5; font-size: .82rem; color: var(--muted); }
  .rt .c-act { order: 6; margin-left: auto; }
  /* Kalender: Punkte statt Beträge (Tippen zeigt die Liste darunter) */
  .cal { gap: .15rem; }
  .cal .day { min-height: 3.4rem; padding: .25rem; border-radius: .6rem; }
  .cal .e { font-size: 0; margin-top: .2rem; justify-content: flex-start; }
  .cal .e::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; display: inline-block; }
}

/* ================= Touch-Geräte: große Tippflächen ================= */
@media (pointer: coarse) {
  .btn { min-height: 2.75rem; padding-inline: 1.1rem; }
  .btn.sm { min-height: 2.5rem; }
  input, select { min-height: 2.9rem; }
  .list .it { padding: .8rem 0; }
}

/* ================= Fernseher / sehr große Bildschirme ================= */
@media (min-width: 1700px) {
  .main { padding-top: 2.25rem; }
  .card { padding: 1.5rem; }
}
@media (min-width: 2200px) {
  .main { max-width: 100rem; }
}
@media (hover: none) and (min-width: 1700px) { .btn:focus-visible, .nav a:focus-visible { outline-width: .3rem; } }

/* Weniger Bewegung, wenn gewünscht */
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
@media print { .side, .fab, #toast { display: none !important; } .shell { display: block; } }
