:root {
  --ink: #252728;
  --muted: #6f6c66;
  --accent: #5c6b4d;
  --accent-soft: #e7ebe1;
  --line: #d9d6cf;
  --bg: #f4f3ef;
  --card: #ffffff;
  --defect: #a2462f;
  --defect-soft: #f6e4de;
  --note: #8a6400;
  --note-soft: #f5ecd5;
  --done: #3f7a4a;
  --done-soft: #e1eee2;
  --radius: 12px;
  --tap: 48px;
  --bar-h: 76px;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px; padding: env(safe-area-inset-top) 12px 0;
  background: var(--ink); color: #fff;
}
.topbar-title { flex: 1; font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  min-width: 44px; height: 44px; border: 0; border-radius: 10px;
  background: transparent; color: inherit; font-size: 26px; line-height: 1; cursor: pointer;
}
.icon-btn:active { background: rgba(255, 255, 255, .12); }
.sync-pill {
  border: 0; border-radius: 99px; padding: 5px 10px; font-size: 13px; font-weight: 700; cursor: pointer;
  background: #4a4d4f; color: #fff; white-space: nowrap;
}
.sync-pill.offline { background: #c9892b; color: #1d1d1d; }
.pending-dot { color: var(--muted); font-size: 15px; }
.topbar .text-btn { background: transparent; border: 0; color: #fff; font-size: 15px; padding: 8px 10px; cursor: pointer; border-radius: 8px; }

/* ---------- Layout ---------- */
.view { max-width: 820px; margin: 0 auto; padding: 16px 16px calc(var(--bar-h) + 24px + env(safe-area-inset-bottom)); }
.stack > * + * { margin-top: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card-link { display: block; text-decoration: none; color: inherit; cursor: pointer; }
.card-link:active { background: #fafaf7; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 2px 8px; font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--ink);
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--defect); border-color: #e6c8bf; }
.btn.block { width: 100%; }
.btn.big { min-height: 60px; font-size: 18px; }
.btn[disabled] { opacity: .5; }
.link-btn { background: none; border: 0; padding: 6px 0; color: var(--accent); font-weight: 600; cursor: pointer; }

/* ---------- Formulare ---------- */
label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 4px 2px; font-weight: 600; }
input[type=text], input[type=password], input[type=search], input[type=date], input[type=time], input[type=email], input[type=tel], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 16px;
}
textarea { resize: vertical; min-height: 110px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.grid3 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
input, select, textarea { min-width: 0; }
input[type=date], input[type=time] { padding-left: 8px; padding-right: 6px; }
.input-row { display: flex; gap: 8px; }
.input-row > input { flex: 1; }

/* Segment-Auswahl Eintragstyp */
.segment { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.segment button {
  min-height: var(--tap); border: 1px solid var(--line); border-radius: 10px; background: #fff; font-weight: 600; cursor: pointer; font-size: 15px;
}
.segment button[aria-pressed=true][data-v=feststellung] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.segment button[aria-pressed=true][data-v=mangel] { background: var(--defect-soft); border-color: var(--defect); color: var(--defect); }
.segment button[aria-pressed=true][data-v=hinweis] { background: var(--note-soft); border-color: var(--note); color: var(--note); }

/* ---------- Badges & Chips ---------- */
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.badge.mangel { background: var(--defect-soft); color: var(--defect); }
.badge.hinweis { background: var(--note-soft); color: var(--note); }
.badge.grey { background: #ecebe6; color: var(--muted); }
.badge.done { background: var(--done-soft); color: var(--done); }
.badge.overdue { background: var(--defect); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 14px; text-align: left;
}
.chip[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.add { border-style: dashed; color: var(--muted); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; background: #e9e7e1; padding: 4px; border-radius: 12px; margin-bottom: 14px; }
.tabs a { flex: 1; text-align: center; padding: 10px 4px; border-radius: 9px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px; white-space: nowrap; }
.tabs a.active { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- Listen ---------- */
.list-title { font-weight: 650; font-size: 17px; }
.meta { font-size: 14px; color: var(--muted); margin-top: 2px; }
.entry-card { cursor: pointer; }
.entry-card .text { margin-top: 6px; white-space: pre-wrap; word-break: break-word; }
.entry-card .text.placeholder { color: var(--muted); font-style: italic; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; margin-top: 10px; }
.thumbs img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: #e9e7e1; display: block; }
.thumbs img.after { outline: 3px solid var(--done); outline-offset: -3px; }
.entry-card.is-done .text { color: var(--muted); }

/* Erledigung eines Mangels */
.resolve { background: #fbfbf9; }
.done-btn { border-color: var(--done); color: var(--done); background: var(--done-soft); }

/* Fotos im Editor */
.photo-edit { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.photo-edit figure { margin: 0; position: relative; }
.photo-edit img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 10px; display: block; background: #e9e7e1; }
.photo-edit input { margin-top: 6px; min-height: 40px; font-size: 14px; padding: 6px 10px; }
.photo-del {
  position: absolute; top: 6px; right: 6px; width: 34px; height: 34px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 18px; cursor: pointer;
}

/* ---------- Untere Aktionsleiste ---------- */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; gap: 8px; justify-content: center;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.96); border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.actionbar .btn { flex: 1; max-width: 220px; min-height: 56px; flex-direction: column; gap: 0; font-size: 13px; padding: 0 6px; }
.actionbar .btn .ico { font-size: 22px; line-height: 1.1; }

/* ---------- Bottom-Sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(20,20,20,.45); }
.sheet {
  position: relative; width: 100%; max-width: 680px; max-height: 92vh; overflow: auto;
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 0 16px calc(16px + env(safe-area-inset-bottom));
  animation: up .18s ease-out;
}
@media (min-width: 760px) {
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 18px; max-height: 88vh; }
}
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.sheet-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px; padding: 14px 0 10px; background: var(--bg); }
.sheet-head h2 { flex: 1; font-size: 18px; }
.sheet-foot { display: flex; gap: 10px; margin-top: 18px; }
.sheet-foot .btn { flex: 1; }

/* ---------- Lightbox / Toast ---------- */
.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 85vh; object-fit: contain; }
.lightbox-cap { color: #ddd; margin-top: 10px; font-size: 14px; text-align: center; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--bar-h) + 20px + env(safe-area-inset-bottom)); z-index: 70;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 15px; max-width: 90vw; box-shadow: 0 4px 14px rgba(0,0,0,.2);
}
.toast.error { background: var(--defect); }

/* ---------- Login ---------- */
.login { max-width: 380px; margin: 10vh auto 0; }
.login img { width: 220px; display: block; margin: 0 auto 28px; }

.weather-line { display: flex; gap: 8px; }
.weather-line input { flex: 1; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
