/* Leihbuch – Stil. Farben als Variablen, Hell- und Dunkelmodus. */
:root {
  color-scheme: light;
  --bg: #F4F2EE; --card: #FFFFFF; --ink: #1C1C1A; --muted: #5F5B54; --line: #DEDAD2; --divider: #EEEBE5;
  --green: #4E7A55; --green-text: #2F5236; --green-tint: #E2EDE3; --green-fill: #DCE8DD; --green-fill-text: #2F5236;
  --orange: #A64A14; --orange-tint: #F6E4D8; --purple-tint: #E7E4F2; --purple: #4A3F8C; --dashed: #8A857C;
  --danger: #A3261B;
  --radius: 16px;
  --font: Manrope, Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121311; --card: #1E1F1D; --ink: #ECEAE5; --muted: #A8A49C; --line: #34352F; --divider: #2A2B27;
    --green: #86A98B; --green-text: #B9D0BB; --green-tint: #243026; --green-fill: #26352A; --green-fill-text: #CFE0CC;
    --orange: #F08A4B; --orange-tint: #3E2A1C; --purple-tint: #2C2940; --purple: #A99DF0; --dashed: #6B675F;
    --danger: #F2877C;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121311; --card: #1E1F1D; --ink: #ECEAE5; --muted: #A8A49C; --line: #34352F; --divider: #2A2B27;
  --green: #86A98B; --green-text: #B9D0BB; --green-tint: #243026; --green-fill: #26352A; --green-fill-text: #CFE0CC;
  --orange: #F08A4B; --orange-tint: #3E2A1C; --purple-tint: #2C2940; --purple: #A99DF0; --dashed: #6B675F;
  --danger: #F2877C;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; }
a { color: var(--green); }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.pos { color: var(--green); }
.neg { color: var(--orange); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.i.s { width: 18px; height: 18px; }

/* Grundgerüst */
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
#view { flex: 1; padding: 16px 20px 24px; display: flex; flex-direction: column; gap: 18px; padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.topbar h1 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; flex: 1; }
.topbar .title { flex: 1; font-size: 17px; font-weight: 700; }
.iconbtn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; text-decoration: none; flex: none; }
.iconbtn.plain { border: none; background: transparent; }
.label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin: 0; }
.section { display: flex; flex-direction: column; gap: 8px; }

/* Navigation unten */
#nav { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
#nav .inner { max-width: 560px; margin: 0 auto; height: 72px; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: center; }
#nav a { display: flex; flex-direction: column; align-items: center; gap: 4px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600; min-height: 44px; justify-content: center; }
#nav a.active { color: var(--green); }
#nav a.plus { justify-self: center; width: 56px; height: 56px; border-radius: 28px; background: var(--ink); color: var(--bg); }
#nav a.plus svg { width: 26px; height: 26px; stroke-width: 2.5; }

/* Aktionsleiste unten (Formulare, Details) */
.actionbar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line); padding: 12px 20px calc(16px + env(safe-area-inset-bottom)); z-index: 10; }
.actionbar .inner { max-width: 520px; margin: 0 auto; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 10px; }

/* Knöpfe */
.btn { min-height: 52px; border-radius: 14px; border: 1px solid var(--ink); background: transparent; color: var(--ink); font-weight: 700; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; cursor: pointer; padding: 0 16px; }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.green { background: var(--green-fill); color: var(--green-fill-text); border-color: var(--green-fill); }
.btn.small { min-height: 36px; font-size: 13px; border-radius: 10px; border-color: var(--line); padding: 0 12px; background: var(--card); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.dashed { border: 1px dashed var(--dashed); min-height: 48px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Karten und Listen */
.card { background: var(--card); border-radius: var(--radius); }
.list { background: var(--card); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; text-decoration: none; color: var(--ink); border: none; background: transparent; width: 100%; text-align: left; cursor: pointer; }
.row + .row { border-top: 1px solid var(--divider); }
.row .main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row .t { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .amt { font-weight: 800; white-space: nowrap; }
.row.static { cursor: default; }
.empty { padding: 20px 16px; color: var(--muted); font-size: 14px; text-align: center; }

.avatar { width: 40px; height: 40px; border-radius: 20px; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex: none; background: var(--divider); color: var(--muted); }
.avatar.sm { width: 36px; height: 36px; font-size: 12px; }
.avatar.pos { background: var(--green-tint); color: var(--green); }
.avatar.neg { background: var(--orange-tint); color: var(--orange); }
.avatar.me { background: var(--ink); color: var(--bg); }
.avatar.grp { border-radius: 12px; background: var(--purple-tint); color: var(--purple); }
.avatar.lg { width: 64px; height: 64px; border-radius: 32px; font-size: 22px; font-weight: 800; }
.ticon { width: 36px; height: 36px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.ticon.pos { background: var(--green-tint); color: var(--green); }
.ticon.neg { background: var(--orange-tint); color: var(--orange); }
.ticon.grp { background: var(--purple-tint); color: var(--purple); }

/* Übersicht */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tile { border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.tile .k { font-size: 13px; font-weight: 600; }
.tile .v { font-size: clamp(20px, 6.4vw, 26px); font-weight: 800; white-space: nowrap; }
.tile .s { font-size: 12px; }
.tile.get { background: var(--green-fill); color: var(--green-fill-text); }
.tile.owe { background: var(--card); border: 2px solid var(--orange); padding: 14px; }
.tile.owe .k, .tile.owe .v { color: var(--orange); }
.tile.owe .s { color: var(--muted); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; text-decoration: none; cursor: pointer; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* Detailkopf */
.hero { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.hero .name { font-size: 20px; font-weight: 800; }
.hero .big { font-size: 34px; font-weight: 800; }
.hero .split { font-size: 12px; color: var(--muted); }
.loan { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.loan + .loan { border-top: 1px solid var(--divider); }
.loan .head { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; }
.bar { height: 8px; border-radius: 4px; background: var(--divider); overflow: hidden; }
.bar span { display: block; height: 8px; width: 0; background: var(--green); }
.bar.neg span { background: var(--orange); }
.groupcard { padding: 16px; display: flex; gap: 14px; align-items: center; }
.groupcard .t { font-size: 19px; font-weight: 800; }
.minis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.mini { background: var(--card); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.mini .k { font-size: 12px; color: var(--muted); }
.mini .v { font-size: 20px; font-weight: 800; }
.total { display: flex; justify-content: space-between; align-items: center; padding: 0 4px; font-weight: 700; }
.total .v { font-size: 20px; font-weight: 800; }
details.exp > summary { list-style: none; }
details.exp > summary::-webkit-details-marker { display: none; }
details.exp + details.exp { border-top: 1px solid var(--divider); }
details.exp .more { padding: 0 16px 14px 64px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
details.exp .more .line { display: flex; justify-content: space-between; }

/* Formulare */
.form { display: flex; flex-direction: column; }
.form > .frow { display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 52px; }
.form > .frow + .frow { border-top: 1px solid var(--divider); }
.frow > label, .frow > .lbl { width: 96px; flex: none; font-size: 13px; color: var(--muted); }
.frow input, .frow select, .frow textarea { flex: 1; min-width: 0; border: none; background: transparent; font-weight: 700; font-size: 16px; padding: 8px 0; outline: none; }
.frow textarea { resize: vertical; min-height: 44px; font-weight: 500; }
.frow input:focus-visible, .frow select:focus-visible, .frow textarea:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; border-radius: 6px; }
.frow select { appearance: none; -webkit-appearance: none; background-image: none; cursor: pointer; }
.frow .link { font-size: 13px; font-weight: 700; color: var(--green); background: none; border: none; cursor: pointer; padding: 8px 0; }
.amount { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px 0; }
.amount label { font-size: 12px; font-weight: 700; color: var(--muted); }
.amount input { width: 100%; border: none; background: transparent; text-align: center; font-size: 40px; font-weight: 800; outline: none; padding: 4px 0; }
.amount input::placeholder { color: var(--line); }
.types { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.type { min-height: 64px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-weight: 700; font-size: 14px; text-align: left; padding: 10px 12px; cursor: pointer; line-height: 1.25; }
.type.on { border: 2px solid var(--green); background: var(--green-tint); color: var(--green-text); padding: 9px 11px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; background: var(--divider); border-radius: 14px; padding: 4px; }
.seg button { min-height: 40px; border-radius: 11px; border: none; background: transparent; font-weight: 700; font-size: 13px; cursor: pointer; color: var(--ink); }
.seg button.on { background: var(--card); color: var(--green-text); box-shadow: 0 1px 2px rgba(0,0,0,0.12); }
.radio { display: flex; align-items: center; gap: 12px; padding: 14px 16px; cursor: pointer; }
.radio + .radio { border-top: 1px solid var(--divider); }
.radio input { width: 20px; height: 20px; accent-color: var(--green); margin: 0; flex: none; }
.radio .main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--green); margin: 0; }
.share { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.share + .share { border-top: 1px solid var(--divider); }
.share .n { flex: 1; font-weight: 700; font-size: 14px; min-width: 0; }
.share input { width: 76px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: transparent; text-align: center; font-weight: 700; font-size: 14px; }
.share input:disabled { opacity: 0.7; }
.share .c { width: 80px; text-align: right; font-weight: 700; font-size: 14px; }
.note { border-radius: 14px; padding: 10px 16px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.note.ok { background: var(--green-tint); color: var(--green-text); }
.note.bad { background: var(--orange-tint); color: var(--orange); }
.note .line { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; }
.memberpick { display: flex; flex-direction: column; }
.memberpick label { display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; font-weight: 600; }
.memberpick label + label { border-top: 1px solid var(--divider); }
.memberpick input { width: 20px; height: 20px; accent-color: var(--green); margin: 0; }
.inline-add { display: flex; gap: 8px; }
.inline-add input { flex: 1; min-width: 0; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); padding: 0 12px; font-size: 16px; }
.month { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin: 8px 4px 0; }
.filters { display: flex; gap: 8px; }
.filters input, .filters select { height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); padding: 0 12px; font-size: 15px; min-width: 0; }
.filters input { flex: 1; }

/* Login / Setup */
.login { max-width: 420px; margin: 0 auto; padding: 48px 20px; display: flex; flex-direction: column; gap: 16px; }
.login h1 { margin: 0; font-size: 30px; font-weight: 800; letter-spacing: -0.02em; }
.login .form { padding: 8px 0; gap: 0; }
.field { display: flex; flex-direction: column; gap: 6px; padding: 10px 16px; font-size: 13px; color: var(--muted); }
.field input { height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); padding: 0 12px; font-size: 16px; color: var(--ink); }
.login .check { padding: 10px 16px; }
.login .btn { margin: 8px 16px 8px; }
.error { color: var(--danger); font-weight: 600; margin: 0; }

/* Meldungen */
#toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: calc(100% - 32px); background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; z-index: 50; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
#toast.show { opacity: 1; }
#toast.err { background: var(--danger); color: #fff; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

@media (min-width: 700px) {
  #view { padding-top: 28px; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

.hint { margin: 0; font-size: 13px; color: var(--muted); }
.sub13 { font-size: 13px; color: var(--muted); }
.warnbar { background: var(--danger); color: #fff; padding: 10px 16px; font-size: 13px; font-weight: 700; text-align: center; }
[hidden] { display: none !important; }
.btn.small.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
