:root {
  --bg: #fff7f2;
  --card: #ffffff;
  --ink: #2b2220;
  --muted: #8a7d78;
  --line: #f0e4dd;
  --accent: #e4572e;
  --accent-soft: #fde6dd;
  --ok: #3a9d23;
  --radius: 16px;
  --tabh: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
input, textarea, select {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff;
  font-size: 16px; outline: none; -webkit-appearance: none; appearance: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
input[type="checkbox"] { width: auto; -webkit-appearance: auto; appearance: auto; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 4px 8px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { min-height: 100%; display: grid; place-items: center; text-align: center; padding: 24px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px; border-radius: 14px; font-weight: 600; background: var(--accent-soft); color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.block { width: 100%; }
.btn.danger { background: #fde4e4; color: #c62828; }
.btn:disabled { opacity: .6; }
.btn:active { transform: scale(.98); }
.icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; font-size: 22px; }
.icon:active { background: var(--line); }

/* ---- Rahmen ---- */
#app { height: 100%; }
.shell { height: 100%; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; justify-content: space-between; padding: calc(10px + var(--safe-t)) 16px 8px; background: var(--bg); }
.top .fam { font-size: 13px; color: var(--muted); }
main { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 14px calc(var(--tabh) + var(--safe-b) + 24px); }
main.chatmode { overflow: hidden; padding-bottom: 0; display: flex; flex-direction: column; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tabh) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(4, 1fr); background: rgba(255,255,255,.94); backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line); z-index: 500;
}
.tabs button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); position: relative; font-weight: 600; }
.tabs button .ti { font-size: 23px; line-height: 1; filter: grayscale(1); opacity: .65; }
.tabs button.on { color: var(--accent); }
.tabs button.on .ti { filter: none; opacity: 1; }
.badge { position: absolute; top: 7px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }

.card { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: 0 1px 2px rgba(80,40,20,.06); }
.stack > * + * { margin-top: 10px; }

/* ---- Einstieg ---- */
.welcome { max-width: 420px; margin: 0 auto; padding: calc(40px + var(--safe-t)) 20px 40px; }
.welcome .logo { width: 84px; height: 84px; border-radius: 22px; display: block; margin: 0 auto 14px; box-shadow: 0 6px 20px rgba(228,87,46,.25); }
.welcome h1 { text-align: center; font-size: 28px; }
.welcome p.lead { text-align: center; color: var(--muted); margin: 6px 0 24px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 14px; font-weight: 600; margin: 0 0 6px 4px; }
.codebox { font: 700 30px/1 ui-monospace, Menlo, monospace; letter-spacing: .08em; text-align: center; padding: 18px; background: #fff; border-radius: 14px; border: 2px dashed var(--accent); color: var(--accent); user-select: all; }
.whochips { display: flex; flex-wrap: wrap; gap: 10px; }
.whochips button { padding: 12px 18px; border-radius: 999px; background: #fff; border: 2px solid var(--line); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.whochips button.on { border-color: currentColor; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px; flex: none; }

/* ---- Kalender ---- */
.monthbar { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 6px; }
.monthbar b { font-size: 18px; }
.cal { background: var(--card); border-radius: var(--radius); padding: 8px 6px 10px; box-shadow: 0 1px 2px rgba(80,40,20,.06); }
.wdays, .grid { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; }
.wdays span { font-size: 12px; color: var(--muted); font-weight: 600; padding: 4px 0; }
.grid button { height: 46px; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 6px; border-radius: 12px; font-size: 15px; }
.grid button.out { color: #cdbfb8; }
.grid button.today .n { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.grid button.sel .n { background: var(--accent); color: #fff; font-weight: 700; }
.grid .n { width: 28px; height: 28px; line-height: 28px; border-radius: 50%; }
.grid .dots { display: flex; gap: 2px; height: 6px; margin-top: 2px; }
.grid .dots i { width: 5px; height: 5px; border-radius: 50%; }
.ev { display: flex; gap: 12px; align-items: stretch; background: var(--card); border-radius: 14px; padding: 12px; box-shadow: 0 1px 2px rgba(80,40,20,.06); width: 100%; text-align: left; }
.ev + .ev { margin-top: 8px; }
.ev .bar { width: 4px; border-radius: 2px; flex: none; }
.ev .t { font-size: 13px; color: var(--muted); min-width: 52px; }
.ev .ti { font-weight: 600; }
.ev .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.ev .when { font-size: 12px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .03em; }
.empty { text-align: center; color: var(--muted); padding: 18px 10px; font-size: 15px; }
.fab { position: fixed; right: 18px; bottom: calc(var(--tabh) + var(--safe-b) + 16px); width: 58px; height: 58px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 32px; line-height: 1; box-shadow: 0 6px 18px rgba(228,87,46,.4); z-index: 400; }
.syncnote { font-size: 12px; color: var(--muted); text-align: center; margin-top: 10px; }
.syncnote.err { color: #c62828; }

/* ---- Einkauf ---- */
.addrow { display: flex; gap: 8px; position: sticky; top: 0; background: var(--bg); padding: 4px 0 10px; z-index: 5; }
.addrow input { flex: 1; }
.addrow .btn { min-width: 52px; padding: 0 16px; font-size: 24px; }
.item { display: flex; align-items: center; gap: 12px; background: var(--card); padding: 6px 6px 6px 12px; border-radius: 14px; min-height: 56px; box-shadow: 0 1px 2px rgba(80,40,20,.06); }
.item + .item { margin-top: 6px; }
.check { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #d8c9c1; flex: none; display: grid; place-items: center; color: #fff; font-size: 16px; }
.item.done .check { background: var(--ok); border-color: var(--ok); }
.item .tx { flex: 1; min-width: 0; }
.item .tx b { font-weight: 500; display: block; overflow-wrap: anywhere; }
.item.done .tx b { text-decoration: line-through; color: var(--muted); }
.item .meta { font-size: 12px; color: var(--muted); }
.item .del { width: 40px; height: 40px; color: #c0b0a8; font-size: 20px; border-radius: 10px; }
.pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: #e8f0ff; color: #2e5fab; margin-left: 4px; vertical-align: 1px; }
.hint { background: #fff; border: 1px dashed #e7d6cc; border-radius: 14px; padding: 12px 14px; font-size: 14px; color: var(--muted); margin-top: 18px; }

/* ---- Chat ---- */
.msgs { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px 0 12px; }
.msg { max-width: 80%; margin: 3px 0; display: flex; flex-direction: column; }
.msg .bub { padding: 9px 13px; border-radius: 18px; background: #fff; box-shadow: 0 1px 2px rgba(80,40,20,.06); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .who { font-size: 12px; font-weight: 700; margin: 6px 0 2px 12px; }
.msg .tm { font-size: 11px; color: var(--muted); margin: 2px 12px 0; }
.msg.me { margin-left: auto; align-items: flex-end; }
.msg.me .bub { background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
.msg:not(.me) .bub { border-bottom-left-radius: 6px; }
.daysep { text-align: center; font-size: 12px; color: var(--muted); margin: 14px 0 6px; font-weight: 600; }
.chatbar { display: flex; gap: 8px; padding: 8px 0 calc(var(--tabh) + var(--safe-b) + 8px); background: var(--bg); }
.chatbar textarea { flex: 1; resize: none; height: 46px; max-height: 120px; border-radius: 23px; padding: 11px 16px; }
.chatbar .btn { border-radius: 23px; min-height: 46px; }

/* ---- Wo ist ---- */
.map { height: 46vh; min-height: 260px; border-radius: var(--radius); overflow: hidden; background: #eee5df; z-index: 1; }
.person { display: flex; align-items: center; gap: 12px; background: var(--card); padding: 12px; border-radius: 14px; box-shadow: 0 1px 2px rgba(80,40,20,.06); }
.person + .person { margin-top: 8px; }
.person .tx { flex: 1; min-width: 0; }
.person .tx b { display: block; }
.person .meta { font-size: 13px; color: var(--muted); }
.person .btn { min-height: 40px; padding: 0 14px; font-size: 14px; }
.pin { width: 36px; height: 36px; border-radius: 50%; border: 3px solid #fff; color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.switchrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 4px; font-size: 15px; }
.toggle { position: relative; width: 52px; height: 32px; flex: none; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle span { position: absolute; inset: 0; background: #e3d6cf; border-radius: 16px; transition: .2s; }
.toggle span::after { content: ""; position: absolute; width: 26px; height: 26px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.toggle input:checked + span { background: var(--ok); }
.toggle input:checked + span::after { transform: translateX(20px); }

/* ---- Blatt (Bottom Sheet) ---- */
.sheet-bg { position: fixed; inset: 0; background: rgba(40,20,10,.35); z-index: 1000; display: flex; align-items: flex-end; animation: fade .2s; }
.sheet { background: var(--bg); width: 100%; max-height: 92vh; overflow-y: auto; border-radius: 22px 22px 0 0; padding: 10px 18px calc(24px + var(--safe-b)); animation: up .25s ease-out; max-width: 640px; margin: 0 auto; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: #e0d2ca; margin: 0 auto 10px; }
.sheet h3 { margin: 4px 0 16px; font-size: 20px; }
.sheet .row { display: flex; gap: 10px; }
.sheet .row > * { flex: 1; min-width: 0; }
.sheet .actions { display: flex; gap: 10px; margin-top: 20px; }
.sheet .actions .btn { flex: 1; }
.sheet section { background: #fff; border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.sheet section h4 { margin: 0 0 8px; font-size: 16px; }
.sheet section p { margin: 6px 0; font-size: 14px; }
.sheet ol { padding-left: 20px; margin: 8px 0; font-size: 14px; }
.sheet ol li { margin: 5px 0; }
.copy { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.copy code { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; font-size: 12px; background: var(--bg); padding: 10px; border-radius: 10px; }
.copy .btn { min-height: 40px; padding: 0 12px; font-size: 14px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

#toast { position: fixed; left: 50%; bottom: calc(var(--tabh) + var(--safe-b) + 90px); transform: translateX(-50%) translateY(20px); background: #2b2220; color: #fff; padding: 11px 18px; border-radius: 14px; font-size: 15px; opacity: 0; pointer-events: none; transition: .25s; z-index: 2000; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }

@media (min-width: 700px) {
  main, .top { max-width: 640px; margin-left: auto; margin-right: auto; width: 100%; }
  .tabs { max-width: 640px; margin: 0 auto; border-radius: 20px 20px 0 0; border: 1px solid var(--line); }
}

/* ---- Kalender: Umschalter + Tagesansicht ---- */
.seg { display: grid; grid-template-columns: 1fr 1fr; background: #f3e7e0; border-radius: 12px; padding: 3px; margin: 2px 0 10px; }
.seg button { height: 36px; border-radius: 10px; font-weight: 600; font-size: 15px; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(80,40,20,.12); }
.dayhead { display: flex; align-items: center; justify-content: space-between; }
.daytitle { display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
.daytitle b { font-size: 20px; }
.daytitle small { font-size: 13px; color: var(--muted); }
.weekstrip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 8px 0 12px; }
.weekstrip button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0 5px; border-radius: 14px; background: #fff; box-shadow: 0 1px 2px rgba(80,40,20,.06); }
.weekstrip .wd { font-size: 11px; font-weight: 600; color: var(--muted); }
.weekstrip .n { font-size: 17px; font-weight: 600; }
.weekstrip .dots { display: flex; gap: 2px; height: 6px; }
.weekstrip .dots i { width: 5px; height: 5px; border-radius: 50%; }
.weekstrip button.today .n { color: var(--accent); }
.weekstrip button.sel { background: var(--accent); box-shadow: 0 3px 10px rgba(228,87,46,.35); }
.weekstrip button.sel .wd, .weekstrip button.sel .n { color: #fff; }
.weekstrip button.sel .dots i { box-shadow: 0 0 0 1.5px #fff; }

#board { overflow: clip; background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(80,40,20,.06); padding: 0 4px 8px; }
.bhead, .ballday, .bbody { display: grid; column-gap: 3px; }
.bhead { position: sticky; top: 0; z-index: 20; background: var(--card); padding: 10px 4px 8px; margin: 0 -4px; border-bottom: 1px solid var(--line); }
.ph { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; padding: 4px 2px; border-radius: 12px; }
.ph.me { background: var(--accent-soft); }
.ph .avatar { width: 32px; height: 32px; font-size: 14px; }
.ph .pn { font-size: 13px; font-weight: 700; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ph .pc { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.ballday { padding: 6px 0; border-bottom: 1px solid var(--line); align-items: start; }
.ballday .hl { font-size: 10px; color: var(--muted); padding-top: 6px; }
.adchip { display: block; width: 100%; text-align: left; font-size: 12px; font-weight: 600; padding: 5px 6px; border-radius: 8px; margin-bottom: 3px;
  background: color-mix(in srgb, var(--c) 18%, white); color: color-mix(in srgb, var(--c) 75%, black); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bbody { position: relative; margin-top: 6px; }
.hours { position: relative; }
.hr { position: absolute; left: 0; right: 4px; transform: translateY(-7px); font-size: 11px; color: var(--muted); text-align: right; }
.hr:first-child { transform: none; }
.lines { position: absolute; inset: 0 0 0 38px; pointer-events: none; }
.lines i { position: absolute; left: 0; right: 0; border-top: 1px solid #f5ece7; }
.col { position: relative; z-index: 2; border-radius: 8px; }
.col:active { background: #fbf4f0; }
.blk { position: absolute; display: flex; flex-direction: column; align-items: flex-start; text-align: left; overflow: hidden; padding: 3px 5px; border-radius: 8px;
  background: color-mix(in srgb, var(--c) 16%, white); border-left: 3px solid var(--c); color: color-mix(in srgb, var(--c) 70%, black); box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.blk .bt { font-size: 10.5px; font-weight: 600; opacity: .85; }
.blk .bn { font-size: 12.5px; font-weight: 700; line-height: 1.2; color: var(--ink); hyphens: auto; -webkit-hyphens: auto; overflow-wrap: break-word; max-width: 100%; display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
.blk.short { flex-direction: row; align-items: center; gap: 4px; padding-top: 0; padding-bottom: 0; }
.blk.short .bn { -webkit-line-clamp: 1 !important; white-space: nowrap; text-overflow: ellipsis; display: block; min-width: 0; }
.blk.short .bt { flex: none; }
.blk.stacked { box-shadow: 0 0 0 1.5px #fff, 0 2px 6px rgba(0,0,0,.12); }
.adchip.span { grid-column: 2 / -1; text-align: center; }
.blk .bl, .blk .by { font-size: 10.5px; opacity: .8; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.blk .by { font-style: italic; }
.now { position: absolute; left: 34px; right: 0; border-top: 2px solid #e53935; z-index: 5; pointer-events: none; }
.now::before { content: ""; position: absolute; left: -4px; top: -5px; width: 8px; height: 8px; border-radius: 50%; background: #e53935; }
.now span { position: absolute; left: -36px; top: -8px; font-size: 10px; font-weight: 700; color: #e53935; background: var(--card); padding: 0 2px; }

/* ---- Dienste ---- */
.calbar { display: flex; gap: 8px; align-items: center; margin: 2px 0 10px; }
.calbar .seg { flex: 1; margin: 0; }
.dienstbtn { min-height: 42px; padding: 0 12px; font-size: 14px; border-radius: 12px; white-space: nowrap; }
.codes { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.codes button { display: flex; flex-direction: column; align-items: center; min-width: 58px; padding: 7px 10px; border-radius: 12px; background: #fff; border: 2px solid var(--line); font-weight: 700; font-size: 15px; }
.codes button small { font-weight: 500; font-size: 10.5px; color: var(--muted); }
.codes button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dgrid { background: #fff; border-radius: 14px; padding: 6px; }
.dcells { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dcells button { height: 52px; border-radius: 10px; background: #faf5f2; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; }
.dcells button.we { background: #f3ece8; }
.dcells button .n { font-size: 13px; color: var(--muted); }
.dcells button .c { font-size: 12.5px; font-weight: 800; min-height: 15px; }
.dcells button.set { background: color-mix(in srgb, var(--c) 22%, white); box-shadow: inset 0 0 0 2px var(--c); }
.dcells button.set .c { color: color-mix(in srgb, var(--c) 75%, black); }
.dcells button.today .n { color: var(--accent); font-weight: 800; }
.coderow { padding: 10px !important; }
.coderow .row { align-items: center; }
.coderow .row > .toggle, .coderow .row > .icon { flex: none; }
