/* Layout: App-Shell mit Kopfzeile (Titel + Plus), Inhalt, Tab-Leiste unten. Durchgehend dunkel. */
:root {
  --bg: #1f1e1d;
  --surface: #2a2927;
  --surface-2: #353431;
  --line: #403e3a;
  --text: #f2f0eb;
  --muted: #a6a39b;
  --accent: #d97757;
  --accent-ink: #1f1e1d;
  --green: #6fb47a;
  --orange: #e0a23c;
  --red: #e0664f;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 14px;
  --tabbar-h: 62px;
  /* Abstand unter der Tab-Leiste: Home-Balken am iPhone + etwas Luft */
  --tabbar-pad: calc(env(safe-area-inset-bottom, 0px) + 14px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.45; }
body { min-height: 100dvh; overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Login ---------- */
.auth {
  min-height: 100dvh; display: grid; place-items: center;
  padding: max(24px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}
.auth-card { width: 100%; max-width: 380px; display: grid; gap: 18px; }
.auth-logo { width: 64px; height: 64px; border-radius: 16px; }
.auth h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.01em; }
.auth p { margin: 0; color: var(--muted); }
.auth form { display: grid; gap: 12px; }
.auth .switch { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 6px 0; cursor: pointer; justify-self: start; }

/* ---------- Shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: calc(env(safe-area-inset-top) + 10px) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 10px; border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar h1 { margin: 0; font-size: 1.25rem; font-weight: 650; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.01em; }
.topbar .sub { display: block; font-size: .8rem; font-weight: 400; color: var(--muted); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid var(--line); background: transparent;
  display: grid; place-items: center; cursor: pointer; flex: none; color: var(--text);
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.plus { border-color: var(--accent); color: var(--accent); }
.icon-btn.plus:active { background: var(--accent); color: var(--accent-ink); }
.icon-btn.ghost { border-color: transparent; }

main#view {
  padding: 8px max(16px, env(safe-area-inset-right)) calc(var(--tabbar-h) + var(--tabbar-pad) + 28px) max(16px, env(safe-area-inset-left));
  max-width: 900px; margin: 0 auto;
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 0 max(8px, env(safe-area-inset-right)) var(--tabbar-pad) max(8px, env(safe-area-inset-left));
}
.tabbar a {
  height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: .72rem; position: relative;
}
.tabbar a svg { width: 23px; height: 23px; }
.tabbar a.active { color: var(--text); }
.tabbar a.active svg { color: var(--accent); }
.tabbar .dot { position: absolute; top: 9px; left: calc(50% + 8px); width: 8px; height: 8px; border-radius: 50%; background: var(--red); }

/* ---------- Bausteine ---------- */
.empty { text-align: center; color: var(--muted); padding: 60px 20px; display: grid; gap: 10px; justify-items: center; }
.empty svg { width: 54px; height: 54px; opacity: .5; }
.empty strong { color: var(--text); font-size: 1.05rem; }
.empty.small { padding: 24px 10px; }

.list { display: grid; gap: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
  display: grid; gap: 8px; color: inherit; text-decoration: none; min-width: 0;
}
a.card:active, button.card:active { background: var(--surface-2); }
button.card { text-align: left; cursor: pointer; width: 100%; }
.card-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.card-row > .grow { flex: 1; min-width: 0; }
.card h3 { margin: 0; font-size: 1.02rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta { color: var(--muted); font-size: .85rem; }
.chev { color: var(--muted); flex: none; width: 18px; height: 18px; }

.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 22px 2px 10px; }
.section-title h2 { margin: 0; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.section-title .meta a, .section-title button.link { font-size: .85rem; }

.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: inherit; background: var(--muted); transition: width .3s; }
.bar.green > span { background: var(--green); }
.bar.orange > span { background: var(--orange); }
.bar.red > span { background: var(--red); }
.bar.big { height: 12px; }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: .75rem; padding: 3px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.green { background: color-mix(in srgb, var(--green) 20%, transparent); color: var(--green); }
.pill.orange { background: color-mix(in srgb, var(--orange) 20%, transparent); color: var(--orange); }
.pill.red { background: color-mix(in srgb, var(--red) 20%, transparent); color: var(--red); }
.pill.accent { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }

.num-badge {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none;
  border: 2px solid var(--line); font-weight: 650; font-variant-numeric: tabular-nums; font-size: .95rem;
}
.num-badge.partial { border-color: var(--orange); color: var(--orange); }
.num-badge.done { border-color: var(--green); background: color-mix(in srgb, var(--green) 18%, transparent); color: var(--green); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); cursor: pointer;
  font-weight: 550; text-decoration: none; white-space: nowrap;
}
.btn svg { width: 19px; height: 19px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--red); background: transparent; border-color: color-mix(in srgb, var(--red) 45%, transparent); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .88rem; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 140px; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }

/* ---------- Formulare ---------- */
.field { display: grid; gap: 6px; }
.field > label, .field > .label { font-size: .82rem; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 84px; resize: vertical; line-height: 1.4; }
.form { display: grid; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  flex: 1 1 auto; min-height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); cursor: pointer; font-size: .9rem;
}
.seg button.on { background: color-mix(in srgb, var(--accent) 18%, var(--surface)); border-color: var(--accent); color: var(--text); }
.check { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: .88rem; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

/* ---------- Objekt / Haus ---------- */
.subtabs { display: flex; gap: 6px; background: var(--surface); padding: 4px; border-radius: 12px; border: 1px solid var(--line); margin: 6px 0 14px; }
.subtabs button { flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; font-weight: 550; }
.subtabs button.on { background: var(--surface-2); color: var(--text); }

.house-wrap { background: radial-gradient(120% 90% at 50% 0%, #2d2b29 0%, var(--bg) 70%); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 0 4px; }
.house-scroll { overflow-x: auto; padding: 0 10px; }
.house-svg { display: block; margin: 0 auto; max-width: none; }
.h-front { fill: #3a3835; stroke: #4c4945; stroke-width: 1; }
.h-side { fill: #2c2a28; stroke: #4c4945; stroke-width: 1; }
.h-roof { fill: #5b3a2e; stroke: #6d4536; }
.h-gable { fill: #46302a; stroke: #6d4536; }
.h-base { fill: #312f2c; }
.h-door { fill: #1f1e1d; stroke: #6a6660; }
.h-canopy { fill: #6a6660; }
.h-line { stroke: #4c4945; stroke-width: 1; }
.h-ground { stroke: #57534d; stroke-width: 2; stroke-linecap: round; }
.h-floor { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.h-label { fill: var(--text); font-size: 12px; font-weight: 600; font-family: var(--font); }
.h-unit { cursor: pointer; }
.h-win { fill: #2a2927; stroke: #55524c; stroke-width: 1; transition: fill .15s; }
.h-unit:hover .h-win, .h-unit:focus .h-win { fill: #3f3c38; }
.h-badge { fill: #1f1e1d; stroke: #8a867e; stroke-width: 2; }
.h-num { fill: var(--text); font-size: 12px; font-weight: 700; font-family: var(--font); }
.u-partial .h-badge { stroke: var(--orange); }
.u-partial .h-num { fill: var(--orange); }
.u-done .h-badge { stroke: var(--green); fill: #24382a; }
.u-done .h-num { fill: var(--green); }
.u-done .h-win { fill: #2b3a2e; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; color: var(--muted); font-size: .78rem; padding: 6px 10px 8px; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; border: 2px solid #8a867e; margin-right: 5px; vertical-align: -1px; }
.legend i.p { border-color: var(--orange); } .legend i.d { border-color: var(--green); background: #24382a; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 4px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .75rem; color: var(--muted); }

.filter { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.filter button { flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 99px; padding: 6px 12px; cursor: pointer; font-size: .85rem; }
.filter button.on { border-color: var(--accent); color: var(--text); }

/* ---------- Wohnung ---------- */
.unit-head { display: flex; gap: 14px; align-items: center; margin: 4px 0 10px; }
.unit-head .num-badge { width: 54px; height: 54px; font-size: 1.15rem; }
.missing { font-size: .8rem; color: var(--muted); }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.photos .ph { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); border: 0; padding: 0; cursor: pointer; }
.photos .ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photos .ph-wrap { position: relative; }
.photos .ph-wrap[hidden] { display: none; }
.photos .ph-wrap .ph { width: 100%; display: block; }
.photos .ph-del { position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border-radius: 50%; border: 0; padding: 0;
  display: grid; place-items: center; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; }
.photos .ph-del svg { width: 16px; height: 16px; }
.photos .ph-del:hover { background: var(--red); }
#toast .toast-btn { background: none; border: 0; padding: 0 0 0 10px; font: inherit; font-weight: 600; color: var(--accent); cursor: pointer; }
.photos .ph .cap { position: absolute; inset: auto 0 0 0; font-size: .65rem; padding: 2px 5px; background: rgba(0,0,0,.55); color: #ddd; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.add-photo { aspect-ratio: 1; border-radius: 10px; border: 1.5px dashed var(--line); display: grid; place-items: center; color: var(--muted); cursor: pointer; background: transparent; }
.add-photo svg { width: 26px; height: 26px; }
.nav-units { display: flex; justify-content: space-between; gap: 10px; margin-top: 20px; }

/* ---------- Vertrieb ---------- */
.doc { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start; }
.doc .tick {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line); background: transparent; cursor: pointer;
  display: grid; place-items: center; color: transparent; margin-top: 1px;
}
.doc .tick svg { width: 16px; height: 16px; }
.doc .tick.requested { border-color: var(--orange); }
.doc .tick.received { border-color: var(--green); background: var(--green); color: var(--accent-ink); }
.doc .tick.na { border-style: dashed; }
.doc.received h3 { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line); }
.doc h3 { white-space: normal; text-overflow: clip; overflow-wrap: anywhere; hyphens: auto; }
.progress-head { display: grid; gap: 8px; }
.progress-head .big { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }

/* ---------- Bottom-Sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50; animation: fade .15s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-height: 92dvh; overflow-y: auto;
  background: var(--surface); border-top: 1px solid var(--line); border-radius: 20px 20px 0 0;
  padding: 10px max(18px, env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  animation: up .2s ease-out; max-width: 720px; margin: 0 auto;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { margin: 0 0 4px; font-size: 1.15rem; }
.sheet .lead { color: var(--muted); margin: 0 0 14px; font-size: .9rem; }
.sheet input, .sheet select, .sheet textarea { background: var(--bg); }
.menu { display: grid; gap: 8px; }
.menu button { display: flex; gap: 12px; align-items: center; text-align: left; padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; }
.menu button svg { width: 22px; height: 22px; color: var(--accent); flex: none; }
.menu button small { display: block; color: var(--muted); font-size: .8rem; }
@keyframes up { from { transform: translateY(30px); opacity: .4; } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop { animation: none; } }

.mic {
  width: 84px; height: 84px; border-radius: 50%; border: 2px solid var(--accent); background: transparent; color: var(--accent);
  display: grid; place-items: center; cursor: pointer; margin: 6px auto 12px;
}
.mic svg { width: 34px; height: 34px; }
.mic.on { background: var(--accent); color: var(--accent-ink); box-shadow: 0 0 0 8px color-mix(in srgb, var(--accent) 22%, transparent); }
.hint { font-size: .82rem; color: var(--muted); }
.notice { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; font-size: .86rem; color: var(--muted); }
.notice.warn { color: var(--orange); }

.plan-house { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 10px; background: var(--bg); }
.plan-floor { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: center; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table.mini { border-collapse: collapse; width: 100%; font-size: .85rem; }
table.mini th, table.mini td { padding: 7px 9px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.mini th { color: var(--muted); font-weight: 500; }
table.mini input { min-height: 34px; padding: 4px 8px; border-radius: 8px; min-width: 64px; }

/* ---------- Bilder ---------- */
.viewer { position: fixed; inset: 0; z-index: 60; background: #000; display: grid; grid-template-rows: auto 1fr auto; }
.viewer header, .viewer footer { padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; display: flex; gap: 8px; align-items: center; color: #ddd; font-size: .85rem; }
.viewer footer { padding: 8px 12px calc(env(safe-area-inset-bottom) + 10px); flex-wrap: wrap; }
.viewer header .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer .img { overflow: auto; display: grid; place-items: center; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + var(--tabbar-pad) + 16px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 80; font-size: .9rem; max-width: calc(100% - 32px);
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
#toast.err { background: var(--red); color: #fff; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.spacer { height: 10px; }

@media (min-width: 760px) {
  .list.cols { grid-template-columns: 1fr 1fr; }
}
.btn-row.compact > .btn { flex: 0 0 auto; }
.menu a.card { display: flex; gap: 12px; align-items: center; padding: 14px; border-radius: 12px; background: var(--bg); text-decoration: none; color: var(--text); }
.menu a.card svg { width: 22px; height: 22px; color: var(--accent); flex: none; }
.menu a.card small { display: block; color: var(--muted); font-size: .8rem; }

/* Sync-Anzeige oben rechts */
.sync-ind { width: 34px; height: 34px; border-radius: 50%; border: 0; background: transparent; display: grid; place-items: center; cursor: pointer; flex: none; color: var(--muted); }
.sync-ind svg { width: 21px; height: 21px; }
.sync-ind.ok { color: var(--green); }
.sync-ind.busy { color: var(--orange); }
.sync-ind.err { color: var(--red); }
.sync-ind.off { color: var(--muted); opacity: .6; }
.auth .btn-row .switch { flex: none; }

/* Avatar (angemeldeter Nutzer) */
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--surface-2); color: var(--text); border: 1.5px solid var(--line);
  font-size: .78rem; font-weight: 700; letter-spacing: .02em; cursor: pointer; padding: 0;
}
.avatar.admin { border-color: var(--accent); color: var(--accent); }
.avatar.big { width: 48px; height: 48px; font-size: 1rem; cursor: default; }
.del-obj { width: 36px; height: 36px; color: var(--muted); }
.del-obj:hover, .del-obj:focus-visible { color: var(--red); }

/* Datumsfelder: iPhone zeichnet sie sonst breiter und mittig */
input[type=date] { -webkit-appearance: none; appearance: none; min-width: 0; display: block; text-align: left; }
input[type=date]::-webkit-date-and-time-value { text-align: left; }
.date-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.date-row input[type=date] { width: auto; flex: 0 1 190px; max-width: 100%; }
.date-row .meta { flex: 1 1 auto; min-width: 0; }
