:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1d2420;
  --muted: #6b736e;
  --line: #e3e0d8;
  --brand: #1f5f4a;
  --brand-ink: #ffffff;
  --brand-soft: #e3efe8;
  --accent: #b8432f;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4e00;
  --done: #9aa39e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141816;
    --card: #1d2320;
    --ink: #e8ece9;
    --muted: #97a19b;
    --line: #2e3632;
    --brand: #4fae8a;
    --brand-ink: #0e1512;
    --brand-soft: #1f3a2f;
    --accent: #f08a74;
    --warn-bg: #3a3016;
    --warn-ink: #f1d58a;
    --done: #66706b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
body.has-nav { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
body.modal-open { overflow: hidden; }
a { color: var(--brand); }
h2 { font-size: 1.25rem; margin: 0 0 0.6rem; }
h3 { font-size: 1.02rem; margin: 0 0 0.5rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.pad { padding: 2rem 1rem; }
.pad-x { padding: 0 1rem; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- Kopfzeile */
#top { position: sticky; top: 0; z-index: 20; background: var(--brand); color: var(--brand-ink); padding-top: env(safe-area-inset-top); }
.bar { display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem 1rem; max-width: 900px; margin: 0 auto; }
.bar .title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.bar .title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .title small { opacity: 0.85; font-size: 0.75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .back { color: inherit; text-decoration: none; font-size: 2rem; line-height: 1; padding: 0 0.3rem 0.2rem 0; }
.bar .logo { font-size: 1.5rem; }
.me { background: rgba(255, 255, 255, 0.18); color: inherit; border: 0; border-radius: 999px; padding: 0.35rem 0.75rem; font: inherit; font-size: 0.85rem; max-width: 7rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.sync { font-size: 0.7rem; padding: 0.15rem 0.5rem; border-radius: 999px; white-space: nowrap; }
.sync.ok { background: rgba(255, 255, 255, 0.15); }
.sync.ok::before { content: '● '; color: #7ee0b0; }
.sync.busy { background: #f3c84b; color: #3a2c00; }
.sync.off { background: var(--accent); color: #fff; }

/* ---------------------------------------------------------------- Navigation */
#nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
#nav:empty { display: none; }
#nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 0.45rem 0 0.55rem; text-decoration: none; color: var(--muted); font-size: 0.72rem; }
#nav a span { font-size: 1.3rem; filter: grayscale(1); opacity: 0.7; }
#nav a.active { color: var(--brand); font-weight: 600; }
#nav a.active span { filter: none; opacity: 1; }

main { max-width: 900px; margin: 0 auto; padding: 0.75rem; }

/* ---------------------------------------------------------------- Bausteine */
.card { display: block; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 0.75rem; color: inherit; text-decoration: none; }
.card.narrow { max-width: 420px; margin: 2rem auto; }
.card.trip { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.card.trip > div { display: flex; flex-direction: column; gap: 0.2rem; }
.card.trip .right { align-items: flex-end; text-align: right; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 0.5rem 0 0.75rem; }
.section-head h2 { margin: 0; }
.danger-zone { border: 1px dashed var(--accent); box-shadow: none; background: transparent; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.3rem; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 10px; padding: 0.6rem 0.95rem; font: inherit; font-size: 0.95rem; cursor: pointer; text-decoration: none; min-height: 44px; }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.btn.danger { color: var(--accent); border-color: var(--accent); }
.btn.small { padding: 0.35rem 0.65rem; min-height: 36px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.5; }
.link { background: none; border: 0; color: var(--brand); text-decoration: underline; font: inherit; cursor: pointer; }
.icon { background: none; border: 0; font-size: 1rem; padding: 0.4rem; cursor: pointer; color: var(--muted); min-width: 36px; min-height: 36px; }

.badge { display: inline-block; font-size: 0.7rem; padding: 0.1rem 0.45rem; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-weight: 600; vertical-align: middle; }
.badge.closed { background: var(--warn-bg); color: var(--warn-ink); }
.badge.archived { background: var(--line); color: var(--muted); }
.badge.new { background: var(--accent); color: #fff; }

.banner { background: var(--warn-bg); color: var(--warn-ink); padding: 0.7rem 0.9rem; border-radius: 12px; margin: 0 0 0.75rem; font-size: 0.9rem; }
.banner.info { background: var(--brand-soft); color: var(--ink); }

input, select, textarea { font: inherit; font-size: 16px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 0.6rem 0.7rem; width: 100%; min-height: 44px; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.form { display: flex; flex-direction: column; gap: 0.7rem; }
.form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.form label > input, .form label > select, .form label > textarea, .form label .row { font-weight: 400; color: var(--ink); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.row { display: flex; gap: 0.5rem; align-items: center; }
.row > input, .row > select { flex: 1; min-width: 0; }
.row.wrap { flex-wrap: wrap; }
.actions { display: flex; gap: 0.5rem; justify-content: flex-end; flex-wrap: wrap; margin-top: 0.4rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.9rem; }
.chip { border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 999px; padding: 0.5rem 0.9rem; font: inherit; cursor: pointer; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* ---------------------------------------------------------------- Toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.75rem; }
.toolbar.sticky { position: sticky; top: calc(52px + env(safe-area-inset-top)); z-index: 10; background: var(--bg); padding: 0.5rem 0; margin-top: -0.5rem; }
.toolbar input[type='search'] { flex: 1 1 140px; }
.toolbar select { width: auto; flex: 0 0 auto; }
.seg { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; font: inherit; font-size: 0.9rem; padding: 0.45rem 0.8rem; border-radius: 9px; color: var(--muted); cursor: pointer; display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
.seg button small { font-size: 0.7rem; opacity: 0.85; }
.seg button.on { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.seg.scroll { max-width: 100%; overflow-x: auto; flex: 1 1 100%; }
.seg.scroll button { flex: 1 0 auto; }
.toggles { display: flex; flex-wrap: wrap; gap: 0.3rem 0.9rem; }
.tog { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.85rem; color: var(--muted); cursor: pointer; }
.tog input { width: 18px; height: 18px; min-height: 0; accent-color: var(--brand); }

/* ---------------------------------------------------------------- Listen */
.group { margin-bottom: 1rem; }
.group > h3 { padding: 0 0.25rem; }
.list { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item { display: flex; gap: 0.75rem; align-items: flex-start; padding: 0.7rem 0.9rem; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item.tap, .item.line { cursor: pointer; }
.item.tap:active, .item.line:active { background: var(--brand-soft); }
.item .main { flex: 1; min-width: 0; }
.item .name { font-weight: 600; overflow-wrap: anywhere; }
.item .fr { color: var(--brand); font-style: italic; font-size: 0.92rem; }
.item .sub { font-size: 0.85rem; color: var(--ink); opacity: 0.8; }
.item .sub::before { content: '↔ '; color: var(--muted); }
.item .comment { font-size: 0.85rem; color: var(--muted); }
.item .meta { font-size: 0.75rem; color: var(--muted); margin-top: 0.15rem; }
.item .qty { font-weight: 700; white-space: nowrap; text-align: right; max-width: 40%; white-space: normal; font-size: 0.95rem; }
.item.dim { opacity: 0.45; }
.list.compact .item { padding: 0.45rem 0.7rem; }
label.imp { display: flex; gap: 0.6rem; align-items: center; width: 100%; cursor: pointer; }
label.imp input { width: 20px; height: 20px; min-height: 0; flex: 0 0 auto; accent-color: var(--brand); }

.dept-head { display: flex; align-items: center; gap: 0.5rem; padding: 0 0.25rem 0.4rem; }
.dept-head h3 { flex: 1; margin: 0; }
.dept-head h3 .fr { color: var(--brand); font-style: italic; font-weight: 400; font-size: 0.85rem; }
.dept-head .count { font-size: 0.8rem; color: var(--muted); }
.claim { border: 1px dashed var(--muted); background: none; color: var(--muted); border-radius: 999px; padding: 0.25rem 0.65rem; font: inherit; font-size: 0.78rem; cursor: pointer; white-space: nowrap; max-width: 9rem; overflow: hidden; text-overflow: ellipsis; }
.claim.taken { border-style: solid; color: var(--ink); }
.claim.mine { border-style: solid; background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.dept.complete .dept-head h3::after { content: ' ✓'; color: var(--brand); }

.cb { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 9px; border: 2px solid var(--brand); background: var(--card); color: var(--brand-ink); font-size: 1.2rem; font-weight: 700; cursor: pointer; margin-top: 1px; display: flex; align-items: center; justify-content: center; }
.cb:disabled { border-color: var(--line); cursor: default; }
.line.done .cb { background: var(--brand); }
.line.sub .cb { background: #d39b2a; border-color: #d39b2a; }
.line.missing .cb { background: var(--accent); border-color: var(--accent); }
.line.done .name, .line.sub .name, .line.missing .name { text-decoration: line-through; color: var(--done); }
.line.done .fr, .line.done .qty, .line.sub .qty, .line.missing .qty { color: var(--done); }
.line.done, .line.sub, .line.missing { background: color-mix(in srgb, var(--card) 80%, var(--bg)); }

.progress { position: relative; height: 26px; background: var(--card); border-radius: 999px; overflow: hidden; margin-bottom: 0.9rem; box-shadow: var(--shadow); }
.progress div { position: absolute; inset: 0 auto 0 0; background: var(--brand-soft); transition: width 0.3s; }
.progress span { position: relative; display: block; text-align: center; font-size: 0.8rem; line-height: 26px; font-weight: 600; }

.fab { position: fixed; right: max(1rem, calc(50% - 440px)); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 15; background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 999px; padding: 0.9rem 1.3rem; font: inherit; font-weight: 700; font-size: 1rem; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25); cursor: pointer; }

/* ---------------------------------------------------------------- Planung */
.edit-row { display: flex; gap: 0.4rem; align-items: center; padding: 0.35rem 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.edit-row:first-child { border-top: 0; }
.edit-row input, .edit-row select { flex: 1 1 140px; width: auto; }
.updown { display: flex; flex-direction: column; }
.updown .icon { min-height: 22px; padding: 0 0.4rem; font-size: 0.7rem; }

/* ---------------------------------------------------------------- Modal */
#modal { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 1.1rem 1rem calc(1rem + env(safe-area-inset-bottom)); box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2); animation: up 0.18s ease-out; }
@media (min-width: 640px) {
  #modal { align-items: center; }
  .sheet { border-radius: 18px; }
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.action-list { display: flex; flex-direction: column; gap: 0.45rem; margin: 0.8rem 0; }
.fr.big { font-size: 1.15rem; color: var(--brand); font-style: italic; margin: -0.3rem 0 0.4rem; }
.sticky-bottom { position: sticky; bottom: -1rem; background: var(--card); padding: 0.6rem 0; }

#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(140px + env(safe-area-inset-bottom)); z-index: 60; display: flex; flex-direction: column; gap: 0.4rem; align-items: center; pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 0.55rem 1rem; border-radius: 999px; font-size: 0.9rem; transition: opacity 0.4s; box-shadow: var(--shadow); }
.toast.err { background: var(--accent); color: #fff; }
.toast.hide { opacity: 0; }

/* ---------------------------------------------------------------- Druck */
.print-preview .sheet-print { background: #fff; color: #000; padding: 1rem; border-radius: 8px; margin-bottom: 1rem; box-shadow: var(--shadow); }
.sheet-print h2 { margin: 0; font-size: 1.2rem; }
.sheet-print h2 small { font-weight: 400; font-style: italic; }
.sheet-print table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-top: 0.5rem; }
.sheet-print th, .sheet-print td { border: 1px solid #999; padding: 0.3rem 0.4rem; text-align: left; vertical-align: top; }
.sheet-print th { background: #eee; }
.sheet-print td.c, .sheet-print th.c { width: 1.8rem; text-align: center; font-size: 1.1rem; }
.sheet-print tr.blank td { height: 1.9rem; }

@media print {
  body { background: #fff; padding: 0 !important; }
  #top, #nav, .fab, .no-print, #toasts, #modal { display: none !important; }
  main { max-width: none; padding: 0; }
  .print-preview .sheet-print { box-shadow: none; padding: 0; margin: 0 0 1.2rem; }
  .sheet-print.break { break-after: page; }
  .sheet-print.break:last-child { break-after: auto; }
  .sheet-print tr { break-inside: avoid; }
}

@media (max-width: 420px) {
  .grid2 { grid-template-columns: 1fr; }
  .item { padding: 0.65rem 0.75rem; }
}

/* Korrekturen */
.form label.tog { flex-direction: row; font-weight: 400; color: var(--muted); }
@media screen { .print-preview .sheet-print { overflow-x: auto; } }

/* Wer hat was bestellt? */
#nav a { font-size: 0.68rem; }
.who-table { border-collapse: collapse; margin: 0.3rem 0 0.2rem; font-size: 0.9rem; }
.who-table td { padding: 0.12rem 0.8rem 0.12rem 0; vertical-align: top; }
.who-table td.q { font-weight: 600; white-space: nowrap; }
.who-table .sub-row td { padding-top: 0; }
.item.order .qty { display: flex; flex-direction: column; align-items: flex-end; }
.item.order .qty small { font-weight: 400; font-size: 0.7rem; }
.st { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 0.1rem 0.5rem; border-radius: 999px; margin-top: 0.25rem; background: var(--line); color: var(--muted); }
.st.done { background: var(--brand-soft); color: var(--brand); }
.st.sub { background: #f6e2b8; color: #6b4e00; }
.st.missing { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.breakdown { margin: 0.4rem 0 0.2rem; }
.breakdown ul { margin: 0.2rem 0 0; padding-left: 1.1rem; }
.breakdown li { margin: 0.15rem 0; }

/* Aktivitäten-Log */
.item.log { align-items: flex-start; gap: 0.6rem; padding: 0.55rem 0.8rem; font-size: 0.92rem; }
.item.log .log-icon { flex: 0 0 auto; font-size: 1rem; line-height: 1.4; }
.item.log.pending { background: var(--warn-bg); }
.log-list .item.log .main { overflow-wrap: anywhere; }
#lineLog { margin: 0.6rem 0 0.2rem; }
#lineLog .list { box-shadow: none; border: 1px solid var(--line); }
