:root {
  --bg: #f5f2ec;
  --surface: #fffdf9;
  --surface-2: #ece7dd;
  --ink: #1f1c17;
  --muted: #655f54;
  --line: #ddd6c9;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe8;
  --danger: #b3372c;
  --holiday: #b3372c;
  --ferien: #fbf0cf;
  --warn-soft: #fde9c8;
  --radius: 16px;
  --tabbar: 68px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15140f;
    --surface: #201e18;
    --surface-2: #2c2921;
    --ink: #f1ede4;
    --muted: #aaa293;
    --line: #3a362c;
    --accent: #5fc3a6;
    --accent-ink: #0c2a22;
    --accent-soft: #1c3a32;
    --danger: #ef8275;
    --holiday: #ef8275;
    --ferien: #362e18;
    --warn-soft: #3d3016;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, .brand {
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, sans-serif;
  margin: 0;
  line-height: 1.2;
  text-wrap: balance;
}
h1 { font-size: 1.7rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .6em; }
small, .hint { color: var(--muted); font-size: .88rem; }
.hint { margin-top: 1.4rem; }
.lead { color: var(--muted); font-weight: 400; margin: .15rem 0 0; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
svg { flex: none; }

/* ---- Grundgerüst ---- */

.shell { min-height: 100dvh; }

.main {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(var(--tabbar) + env(safe-area-inset-bottom) + 96px);
}

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }

section { margin-top: 26px; }
section > h2 { margin-bottom: 10px; }

.nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav .brand, .nav .nav-add, .nav .nav-me { display: none; }

.nav-item {
  min-height: var(--tabbar);
  background: none;
  border: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: .74rem;
  color: var(--muted);
}
.nav-item.on { color: var(--accent); font-weight: 600; }
.nav-icon { position: relative; display: grid; }
.badge {
  position: absolute; top: -6px; right: -12px;
  min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px;
  background: var(--danger); color: #fff;
  font-size: .72rem; font-weight: 700; line-height: 20px; text-align: center;
}

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 16px);
  z-index: 6;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px; padding: 0 22px 0 18px;
  border: 0; border-radius: 28px;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 700;
  box-shadow: 0 6px 18px rgb(0 0 0 / .22);
}

/* ---- Bausteine ---- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px;
  border: 1.5px solid var(--line); border-radius: 14px;
  background: var(--surface);
  font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.btn.small { min-height: 40px; padding: 0 14px; font-size: .92rem; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

.icon-btn {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--surface-2);
}

.link { background: none; border: 0; padding: 12px 0; color: var(--accent); font-weight: 600; text-decoration: underline; }

.avatar {
  flex: none;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--pc, var(--accent)); color: #fff;
  font-weight: 700;
}
.avatar.xl { width: 60px; height: 60px; font-size: 1.5rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-top: 16px;
}
.card h2 { margin-bottom: 8px; }
.card > :last-child { margin-bottom: 0; }
details.card summary { cursor: pointer; list-style: none; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary h2 { display: inline-block; margin-bottom: 2px; }
details.card summary h2::after { content: " ▾"; color: var(--muted); }
details.card[open] summary h2::after { content: " ▴"; }
details.card[open] summary { margin-bottom: 12px; }
details.card summary .ev-sub { display: block; }

.person-card { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.person-card > div { flex: 1; min-width: 120px; display: flex; flex-direction: column; }

.empty { color: var(--muted); padding: 14px 0; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tag { padding: 4px 12px; border-radius: 999px; font-size: .88rem; font-weight: 600; }
.tag.hol { background: color-mix(in srgb, var(--holiday) 14%, transparent); color: var(--holiday); }
.tag.fer { background: var(--ferien); }

/* ---- Terminzeilen ---- */

.ev, .notice {
  width: 100%;
  display: flex; align-items: center; gap: 12px;
  min-height: 64px; padding: 10px 14px;
  margin-bottom: 8px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 6px solid var(--pc);
  border-radius: 14px;
}
.notice { border-left-width: 1px; }
.notice.unread { background: var(--accent-soft); border-color: transparent; }
.notice.unread .ev-title { font-weight: 700; }

.ev-time { flex: none; width: 54px; font-weight: 700; font-variant-numeric: tabular-nums; font-size: .95rem; }
.ev-body { min-width: 0; display: flex; flex-direction: column; }
.ev-title { font-weight: 600; overflow-wrap: anywhere; }
.ev-sub { color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.lock { display: inline-block; vertical-align: -2px; margin-left: 6px; color: var(--muted); }
.lock svg { width: 16px; height: 16px; }

.day-head { margin: 16px 0 8px; color: var(--muted); }

.remind {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px 10px 16px; margin-bottom: 8px;
  background: var(--warn-soft);
  border-radius: 14px;
}
.remind.strong { box-shadow: inset 0 0 0 2px var(--danger); }
.remind-text { flex: 1; min-width: 0; display: flex; flex-direction: column; text-align: left; background: none; border: 0; padding: 4px 0; }

.quick label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 6px; }
.quick-row { display: flex; gap: 8px; }
.quick-row input { flex: 1; min-width: 0; }
.quick-row .btn { width: 52px; padding: 0; flex: none; }

input[type=text], input[type=date], input[type=time], select, textarea {
  width: 100%;
  min-height: 50px; padding: 10px 14px;
  background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 14px;
  appearance: none; -webkit-appearance: none;
}
select {
  padding-right: 40px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 22px) 55%, calc(100% - 16px) 55%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
}
textarea { resize: vertical; }
::placeholder { color: var(--muted); opacity: .8; }

/* ---- Auswahl-Knöpfe ---- */

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 16px; }
.seg button {
  min-height: 44px; border: 0; border-radius: 12px;
  background: none; font-weight: 600; color: var(--muted);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.seg button svg { width: 18px; height: 18px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / .14); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn {
  min-height: 44px; padding: 0 14px;
  border: 1.5px solid var(--line); border-radius: 999px;
  background: var(--surface);
}
.chip-btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip-btn.person.on { background: var(--pc); border-color: var(--pc); color: #fff; }

.field { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; }
.field > span:first-child { font-weight: 600; font-size: .92rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.row .field { min-width: 0; }
.row .field:first-child { grid-column: 1 / -1; }
@media (min-width: 560px) {
  .row { grid-template-columns: 1.3fr 1fr 1fr; }
  .row .field:first-child { grid-column: auto; }
}
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; margin-top: 6px; }
.check input { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }

/* ---- Kalender ---- */

.cal { margin-top: 16px; }
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.cal-head h2 { flex: 1; text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-wd { text-align: center; font-size: .8rem; color: var(--muted); padding: 4px 0; }

.day {
  min-height: 58px; padding: 5px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden;
}
.day.out { opacity: .45; }
.day.ferien { background: var(--ferien); }
.day.sel { outline: 3px solid var(--accent); outline-offset: -2px; }
.num { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; font-weight: 600; }
.day.hol .num { color: var(--holiday); }
.day.today .num { background: var(--accent); color: var(--accent-ink); }
.dots { display: flex; gap: 3px; min-height: 8px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--pc); }
.labels { display: none; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: .88rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

.day-panel h2 .lead { font-size: 1rem; }

/* ---- Wer bist du? ---- */

.who { max-width: 460px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 56px) 20px 40px; text-align: center; }
.who h1 { font-size: 2.2rem; }
.who-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 28px; }
.who-btn {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 22px 10px;
  background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 20px;
  font-weight: 700; font-size: 1.1rem;
}

.who-btn:disabled { opacity: .45; cursor: default; }
.who-btn.armed { border-color: var(--pc); box-shadow: inset 0 0 0 2px var(--pc); }
.who-btn .ev-sub { font-weight: 400; }
.login { text-align: left; margin-top: 12px; }
.login .btn { margin-top: 20px; }
input[type=email], input[type=password] {
  width: 100%;
  min-height: 50px; padding: 10px 14px;
  background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 14px;
}
.btn:disabled { opacity: .6; cursor: default; }

/* ---- Formular (von unten eingeschoben) ---- */

dialog#sheet {
  width: 100%; max-width: 560px; max-height: 92dvh;
  margin: auto auto 0;
  padding: 0; border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--bg); color: var(--ink);
  overflow-y: auto;
  overscroll-behavior: contain;
}
dialog#sheet::backdrop { background: rgb(0 0 0 / .45); }
.form { padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-foot {
  position: sticky; bottom: 0;
  display: flex; gap: 10px;
  margin: 22px -18px calc(-18px - env(safe-area-inset-bottom));
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.sheet-foot .primary { flex: 1; }
.form-error { margin: 16px 0 0; padding: 12px 14px; border-radius: 12px; background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); font-weight: 600; }

.facts { margin: 16px 0 0; }
.facts div { padding: 10px 0; border-bottom: 1px solid var(--line); }
.facts dt { color: var(--muted); font-size: .88rem; }
.facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

#toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 14px);
  z-index: 20;
  transform: translate(-50%, -20px);
  width: max-content; max-width: min(92vw, 460px); padding: 12px 18px;
  border-radius: 14px;
  background: var(--ink); color: var(--bg);
  font-weight: 600; text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- iPad quer und Mac: Leiste links, Kalender mit Terminnamen ---- */

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); }
  .nav {
    position: sticky; top: 0;
    height: 100dvh;
    display: flex; flex-direction: column; align-items: stretch; gap: 4px;
    padding: 24px 14px;
    border-top: 0; border-right: 1px solid var(--line);
    background: var(--surface);
  }
  .nav .brand { display: block; font-size: 1.5rem; font-weight: 700; padding: 0 10px 14px; }
  .nav .nav-add { display: inline-flex; margin-bottom: 14px; }
  .nav-item { flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 50px; padding: 0 12px; border-radius: 12px; font-size: 1rem; }
  .nav-item.on { background: var(--accent-soft); }
  .nav .nav-me {
    display: flex; align-items: center; gap: 10px;
    margin-top: auto; padding: 10px;
    background: none; border: 0; border-radius: 12px;
    font-weight: 600; text-align: left;
  }
  .fab { display: none; }
  .main { max-width: 1180px; margin: 0; padding: 32px 36px 48px; }
  .main > .quick, .main > section, .main > .card, .main > .notice, .main > .seg { max-width: 720px; }

  .cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 28px; align-items: start; max-width: none; }
  .day-panel { margin-top: 16px; }
  .day { min-height: 104px; align-items: stretch; padding: 6px; }
  .dots { display: none; }
  .labels { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
  .lab {
    padding: 1px 5px;
    border-left: 3px solid var(--pc);
    border-radius: 4px;
    background: color-mix(in srgb, var(--pc) 16%, transparent);
    font-size: .74rem; line-height: 1.25; text-align: left;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
    overflow: hidden; overflow-wrap: anywhere;
  }
  .lab.holname { border-left: 0; background: none; color: var(--holiday); font-weight: 600; padding-left: 0; }
  .lab.more { border-left: 0; background: none; color: var(--muted); }

  dialog#sheet { margin: auto; border-radius: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
