/* Forum Orga – PWA-Demo. Bewusst ohne Framework und ohne Build-Schritt. */

:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --surface-2: #ebe6de;
  --text: #1c1a18;
  --muted: #6f6962;
  --line: rgba(28, 26, 24, .13);
  --accent: #5a4a8f;
  --accent-ink: #ffffff;
  --accent-soft: rgba(90, 74, 143, .12);
  --green: #2e7d4f;
  --amber: #b77c14;
  --red: #c2412f;
  --header-h: 50px;
  --tabbar-h: 54px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121110;
    --surface: #1e1c1a;
    --surface-2: #2b2825;
    --text: #eeeae4;
    --muted: #a39d95;
    --line: rgba(238, 234, 228, .13);
    --accent: #a898e8;
    --accent-ink: #17142a;
    --accent-soft: rgba(168, 152, 232, .16);
    --green: #46a771;
    --amber: #d39b33;
    --red: #e05f4b;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
}

body {
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
b, strong { font-weight: 600; }

/* ---------- Rahmen: folgt dem sichtbaren Bereich (Tastatur!) ---------- */

#app {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--app-top, 0px);
  height: var(--app-h, 100dvh);
  overflow: hidden;
}

.shell {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  transition: transform .34s var(--ease);
}
.detail-open .shell { transform: translate3d(-25%, 0, 0); }

.topbar {
  flex: none;
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: 110px 1fr 110px;
  align-items: center;
  height: calc(var(--header-h) + var(--sat));
  padding: var(--sat) calc(4px + var(--sar)) 0 calc(4px + var(--sal));
  background: var(--bg);
  border-bottom: .5px solid var(--line);
  user-select: none;
  -webkit-user-select: none;
}
.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  justify-self: end;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--accent);
}
.icon-btn svg { width: 26px; height: 26px; }
.back-btn {
  justify-self: start;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 0;
  padding-right: 8px;
  color: var(--accent);
}
.back-btn svg { width: 26px; height: 26px; stroke-width: 2.4; }
.icon-btn:active, .back-btn:active, .link:active { opacity: .35; }

.offline-bar {
  flex: none;
  padding: 4px 8px;
  background: var(--amber);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

/* ---------- Ansichten: bleiben im DOM, merken sich die Scroll-Position ---------- */

#views { position: relative; flex: 1; min-height: 0; }

.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  visibility: hidden;
  pointer-events: none;
}
.view.active { visibility: visible; pointer-events: auto; }

.scroller {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 var(--sar) 28px var(--sal);
  background: var(--bg);
  transition: transform .3s var(--ease);
}
/* Oberflächentext wird nicht markiert (wie in nativen Apps), Eingaben und Notizen schon. */
.shell, .page, .sheet, .as-wrap { user-select: none; -webkit-user-select: none; }
#list-scroller { -webkit-touch-callout: none; }
input, textarea, .note { user-select: text; -webkit-user-select: text; }

/* ---------- Ziehen zum Aktualisieren ---------- */

.ptr {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 0;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  opacity: 0;
  transform: translate3d(0, -56px, 0);
  transition: transform .3s var(--ease), opacity .3s;
  pointer-events: none;
}
.ptr-arrow { width: 20px; height: 20px; transition: transform .2s var(--ease); }
.ptr.armed .ptr-arrow { transform: rotate(180deg); }
.spinner {
  display: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2.5px solid var(--line);
  border-top-color: var(--muted);
  animation: spin .8s linear infinite;
}
.ptr.loading .spinner { display: block; }
.ptr.loading .ptr-arrow { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Hinweise oben in der Liste ---------- */

.howto {
  position: relative;
  margin: 12px 16px 0;
  padding: 12px 44px 12px 14px;
  border-radius: 12px;
  background: var(--accent-soft);
  font-size: 14px;
  line-height: 1.4;
}
.howto ul { margin: 6px 0 0; padding-left: 18px; }
.howto li { margin: 3px 0; }
.howto .x {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.howto .x svg { width: 18px; height: 18px; }

.install-tip {
  display: flex;
  align-items: center;
  gap: 10px;
  width: calc(100% - 32px);
  margin: 12px 16px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface);
  border: .5px solid var(--line);
  font-size: 14px;
  line-height: 1.35;
  text-align: left;
}
.install-tip svg { flex: none; width: 26px; height: 26px; color: var(--accent); }
.install-tip:active { background: var(--surface-2); }

/* ---------- Liste ---------- */

.group { position: relative; }
.group-h {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0;
  padding: 18px 20px 6px;
  background: var(--bg);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  user-select: none;
  -webkit-user-select: none;
}
.group-h .count { margin-left: 4px; font-weight: 500; opacity: .8; }

.rows {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border-top: .5px solid var(--line);
  border-bottom: .5px solid var(--line);
}

.row {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.row + .row .row-content::before {
  content: "";
  position: absolute;
  top: 0;
  left: 52px;
  right: 0;
  border-top: .5px solid var(--line);
}

.row-content {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 64px;
  padding: 8px 12px 8px 4px;
  background: var(--surface);
  touch-action: pan-y;
  transition: transform .3s var(--ease), background-color .15s;
}
.row.pressed .row-content { background: var(--surface-2); }
.row.dragging .row-content, .row.dragging .row-actions { transition: none; }

.check {
  flex: none;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
}
.check svg { width: 26px; height: 26px; color: var(--muted); stroke-width: 1.6; }
.check path { opacity: 0; }
.row.done .check svg { color: var(--green); }
.row.done .check circle { fill: var(--green); }
.row.done .check path { opacity: 1; stroke: #fff; stroke-width: 2.4; }

.row-text { flex: 1; min-width: 0; }
.row-title { font-size: 17px; line-height: 1.25; }
.row-meta { margin-top: 2px; font-size: 14px; color: var(--muted); }
.row.done .row-title { color: var(--muted); text-decoration: line-through; }
.chev { flex: none; width: 18px; height: 18px; color: var(--muted); opacity: .55; }

.row-actions {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 0;
  display: flex;
  visibility: hidden;
  transition: width .3s var(--ease);
}
.row-actions.left { left: 0; width: 96px; }
.row-actions.right { right: 0; width: 168px; }
.row[data-side="left"] .row-actions.left,
.row[data-side="right"] .row-actions.right { visibility: visible; }

.act {
  flex: 0 0 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}
.act-done { flex: 1 0 96px; background: var(--green); }
.act-later { background: var(--amber); }
.act-delete { flex-grow: 1; background: var(--red); }
.row.full .act-later { display: none; }
.row.full .act-delete { justify-content: flex-start; padding-left: 24px; }
.row.full .act-done { justify-content: flex-end; padding-right: 24px; }

.row.lifted {
  z-index: 3;
  border-radius: 12px;
  transform: scale(1.03);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .2);
  transition: transform .2s var(--ease), box-shadow .2s;
}
.row.collapsing { opacity: 0; transition: height .26s var(--ease), opacity .2s; }
.row.flash .row-content { animation: flash 1.6s ease-out; }
@keyframes flash {
  0%, 35% { background: var(--accent-soft); }
  100% { background: var(--surface); }
}

.empty { padding: 48px 24px; text-align: center; color: var(--muted); }

/* ---------- Formulare ---------- */

.section-h {
  margin: 0;
  padding: 24px 32px 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: .02em;
  text-transform: uppercase;
}
.hint { margin: 7px 32px 0; color: var(--muted); font-size: 13px; line-height: 1.4; }
.hint.no-top { margin-top: 0; }
.pad { padding: 16px; }

.card {
  margin: 0 16px;
  overflow: hidden;
  border-radius: 12px;
  background: var(--surface);
}
.card + .card { margin-top: 16px; }

.field {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 0 16px;
}
.field.top { align-items: flex-start; }
.field.top > label { padding-top: 12px; }
.field + .field::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  border-top: .5px solid var(--line);
}
.field > label, .field > span { flex: 0 0 100px; }

.field input:not([type="checkbox"]),
.field select,
.field textarea {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  padding: 12px 0;
  border: 0;
  border-radius: 0;
  outline: 0;
  background: transparent;
  font-size: 17px; /* ab 16 px zoomt das iPhone beim Antippen nicht */
  caret-color: var(--accent);
}
.field textarea { resize: none; line-height: 1.35; min-height: 46px; }
::placeholder { color: var(--muted); opacity: .7; }

.field select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 18px;
  color: var(--muted);
  text-align: right;
  text-align-last: right;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a847c' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 6l6 6-6 6'/%3E%3C/svg%3E") no-repeat right center / 13px;
}
.field input[type="date"],
.field input[type="time"] {
  -webkit-appearance: none;
  appearance: none;
  color: var(--accent);
  text-align: right;
}
.field input[type="date"]::-webkit-date-and-time-value,
.field input[type="time"]::-webkit-date-and-time-value { text-align: right; }

input.code { letter-spacing: .3em; font-variant-numeric: tabular-nums; }
#f-small { font-size: 14px !important; }

.switch-field { justify-content: space-between; cursor: pointer; }
.switch-field input { width: 22px; height: 22px; margin: 0; accent-color: var(--green); }

.stepper { flex: 1; display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.stepper button {
  width: 40px;
  height: 34px;
  border-radius: 9px;
  background: var(--surface-2);
  font-size: 22px;
  line-height: 1;
}
.stepper button:active { opacity: .5; }
.field .stepper input { flex: 0 0 44px; text-align: center; font-variant-numeric: tabular-nums; }

.note-area {
  display: block;
  width: 100%;
  min-height: 96px;
  padding: 12px 16px;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 17px;
  resize: none;
  caret-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  padding: 0 20px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 17px;
  font-weight: 600;
  transition: transform .12s, opacity .12s;
}
.btn:active { transform: scale(.97); opacity: .85; }
.btn.block { display: flex; width: 100%; }

.shake { animation: shake .4s; }
@keyframes shake {
  0%, 100% { transform: none; }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

/* ---------- Notizen und Eingabeleiste ---------- */

.notes { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; padding: 0 16px; }
.note {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 18px 18px 4px 18px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 16px;
  line-height: 1.3;
  overflow-wrap: anywhere;
  user-select: text;
  -webkit-user-select: text;
}
.note small { display: block; margin-top: 2px; font-size: 11px; opacity: .75; text-align: right; }
.note.pending { opacity: .6; }
.notes-empty { align-self: stretch; padding: 8px; color: var(--muted); font-size: 14px; text-align: center; }

.composer {
  flex: none;
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 8px calc(10px + var(--sar)) 8px calc(10px + var(--sal));
  background: var(--bg);
  border-top: .5px solid var(--line);
}
.composer input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 16px;
  border: .5px solid var(--line);
  border-radius: 20px;
  outline: 0;
  background: var(--surface);
  font-size: 17px;
  caret-color: var(--accent);
}
.composer button {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: var(--accent);
  color: var(--accent-ink);
  transition: opacity .15s, transform .12s;
}
.composer button:disabled { opacity: .3; }
.composer button:active { transform: scale(.92); }
.composer button svg { width: 20px; height: 20px; stroke-width: 2.4; }

/* ---------- Tab-Leiste ---------- */

.tabbar {
  flex: none;
  position: relative;
  z-index: 3;
  display: flex;
  padding: 0 var(--sar) var(--sab) var(--sal);
  background: var(--surface);
  border-top: .5px solid var(--line);
  user-select: none;
  -webkit-user-select: none;
}
.tab {
  flex: 1;
  height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
}
.tab svg { width: 25px; height: 25px; stroke-width: 1.8; transition: transform .12s; }
.tab:active svg { transform: scale(.88); }
.tab.active { color: var(--accent); }

/* Tastatur offen: Tab-Leiste weg, wie in nativen Apps */
.kb-open .tabbar { display: none; }

/* ---------- Detailseite ---------- */

.page {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  visibility: hidden;
  transform: translate3d(100%, 0, 0);
  transition: transform .34s var(--ease), visibility 0s linear .34s;
  touch-action: pan-y;
}
.page.open {
  visibility: visible;
  transform: none;
  box-shadow: -10px 0 30px rgba(0, 0, 0, .14);
  transition: transform .34s var(--ease), visibility 0s;
}
.page-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 0 var(--sar) calc(32px + var(--sab)) var(--sal);
}
.detail-title { margin: 18px 20px 18px; font-size: 28px; font-weight: 700; line-height: 1.15; }

/* ---------- Blatt von unten ---------- */

.backdrop {
  position: absolute;
  inset: 0;
  z-index: 8;
  background: rgba(0, 0, 0, .38);
  opacity: 0;
  pointer-events: none;
  transition: opacity .32s;
}
.backdrop.show { opacity: 1; pointer-events: auto; }

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9;
  display: flex;
  flex-direction: column;
  max-height: calc(100% - 20px - var(--sat));
  padding-bottom: var(--sab);
  border-radius: 14px 14px 0 0;
  background: var(--bg);
  box-shadow: 0 -6px 30px rgba(0, 0, 0, .18);
  transform: translate3d(0, 105%, 0);
  transition: transform .36s var(--ease);
}
.sheet.open { transform: none; }
.kb-open .sheet { padding-bottom: 0; }
.sheet-drag { flex: none; touch-action: none; user-select: none; -webkit-user-select: none; }
.sheet-grab { height: 18px; display: grid; place-items: center; }
.sheet-grab span { width: 38px; height: 5px; border-radius: 3px; background: var(--line); }
.sheet-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 calc(8px + var(--sar)) 8px calc(8px + var(--sal));
}
.sheet-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.link { justify-self: start; min-height: 44px; padding: 0 8px; color: var(--accent); font-size: 17px; }
.link.strong { justify-self: end; font-weight: 600; }
.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  margin: 0;
  padding: 4px var(--sar) 20px var(--sal);
}

/* ---------- Aktionsblatt ---------- */

.as-wrap {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 8px;
  padding: 8px calc(8px + var(--sar)) calc(8px + var(--sab)) calc(8px + var(--sal));
  background: rgba(0, 0, 0, 0);
  transition: background .25s;
}
.as-wrap.show { background: rgba(0, 0, 0, .38); }
.as-group {
  overflow: hidden;
  border-radius: 14px;
  background: var(--surface);
  transform: translate3d(0, 130%, 0);
  transition: transform .32s var(--ease);
}
.as-wrap.show .as-group { transform: none; }
.as-title { padding: 14px 16px; color: var(--muted); font-size: 13px; text-align: center; }
.as-btn {
  display: block;
  width: 100%;
  min-height: 56px;
  border-top: .5px solid var(--line);
  color: var(--accent);
  font-size: 19px;
}
.as-group > .as-btn:first-child { border-top: 0; }
.as-btn:active { background: var(--surface-2); }
.as-btn.destructive { color: var(--red); }
.as-cancel { font-weight: 600; }

/* ---------- Meldung unten ---------- */

.toast {
  position: absolute;
  left: calc(12px + var(--sal));
  right: calc(12px + var(--sar));
  bottom: calc(var(--tabbar-h) + var(--sab) + 10px);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 10px 10px 10px 16px;
  border-radius: 14px;
  background: #2a2724;
  color: #fff;
  font-size: 15px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  opacity: 0;
  transform: translate3d(0, 16px, 0);
  pointer-events: none;
  transition: transform .25s var(--ease), opacity .2s;
}
.toast.show { opacity: 1; transform: none; pointer-events: auto; }
.toast span { flex: 1; }
.toast button { min-height: 36px; padding: 0 8px; color: #cbbfff; font-weight: 600; }
.kb-open .toast { bottom: 10px; }

/* ---------- Gerät ---------- */

.cell {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 50px;
  padding: 10px 16px;
  color: var(--accent);
  font-size: 17px;
  text-align: left;
  cursor: pointer;
}
.cell + .cell::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  border-top: .5px solid var(--line);
}
.cell:active { background: var(--surface-2); }
.cell.static { color: var(--text); cursor: default; }
.cell.static:active { background: none; }
.cell.danger { color: var(--red); }
.dot { flex: none; width: 10px; height: 10px; border-radius: 5px; background: var(--green); }

.steps { margin: 0; padding: 12px 16px 12px 38px; line-height: 1.5; }
.steps li { margin: 2px 0; }
.steps svg { width: 18px; height: 18px; vertical-align: -3px; color: var(--accent); }

.kv { margin: 0; }
.kv > div { position: relative; display: flex; justify-content: space-between; gap: 16px; padding: 11px 16px; }
.kv > div + div::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  border-top: .5px solid var(--line);
}
.kv dt { flex: none; }
.kv dd { margin: 0; color: var(--muted); text-align: right; }

#photo-preview { display: block; max-width: calc(100% - 32px); margin: 12px 16px 0; border-radius: 12px; }
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; clip: rect(0 0 0 0); }

#sa-probe {
  position: fixed;
  top: 0;
  left: 0;
  visibility: hidden;
  pointer-events: none;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
