:root {
  color-scheme: light dark;
  --bg: #f5f3ee;
  --surface: #ffffff;
  --ink: #1d2422;
  --muted: #5e6864;
  --line: #d9d6cd;
  --accent: #1c5d58;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe8;
  --danger: #a82f26;
  --danger-ink: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151a18;
    --surface: #1f2623;
    --ink: #edeae3;
    --muted: #a3ada8;
    --line: #36403c;
    --accent: #6cc7bb;
    --accent-ink: #0f2421;
    --accent-soft: #24403c;
    --danger: #f08a7f;
    --danger-ink: #2c0c09;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0 auto;
  max-width: 720px;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

html { background: var(--bg); }

h2 { margin: 0 0 16px; font-size: 1.25rem; }
h3 { margin: 0 0 6px; font-size: 1rem; }

button, input, textarea, select { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Kopfzeile */
.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}

.object-btn {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 2px 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}

.object-name, .object-address {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.object-name { font-size: 1.15rem; font-weight: 650; }
.object-address { color: var(--muted); font-size: 0.875rem; }

/* Rubriken */
.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 0 8px;
}

.tab {
  position: relative;
  min-height: 52px;
  padding: 6px 2px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 550;
  cursor: pointer;
}

.tab[aria-selected="true"] { color: var(--ink); font-weight: 700; }

.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset: auto 6px -1px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--accent);
}

.tab-count {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  min-height: 1.1em;
}

/* Inhalt */
.panel { padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }

.editor {
  display: grid;
  gap: 10px;
}

.composer {
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.editor textarea {
  display: block;
  width: 100%;
  min-height: 84px;
  max-height: 50vh;
  padding: 10px;
  resize: none;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.editor-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.editor-row .spacer { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}

.btn svg { width: 20px; height: 20px; flex: none; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--danger-ink); }
.btn-danger-quiet { color: var(--danger); }
.btn-quiet { background: none; }
.btn-small { min-height: 40px; padding: 0 10px; border: 0; background: none; color: var(--muted); font-size: 0.875rem; }

.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.thumbs:empty { display: none; }

.thumb { position: relative; aspect-ratio: 1; }

.thumb-open {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: 6px;
  overflow: hidden;
  background: var(--line);
  cursor: zoom-in;
}

.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }

.thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgb(0 0 0 / 0.65);
  color: #fff;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.field {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
  font-size: 0.875rem;
  font-weight: 550;
}

.field input, .field select {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 400;
}

/* Einträge */
.entries {
  display: grid;
  gap: 10px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

.entries:empty { display: none; }

.entry {
  display: grid;
  gap: 8px;
  padding: 12px 12px 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.entry-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.entry-foot { display: flex; align-items: center; gap: 2px; }

.entry-time {
  flex: 1;
  color: var(--muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.empty { margin: 28px 8px; color: var(--muted); text-align: center; }

/* Dialoge */
.sheet {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 20px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.sheet-small { width: min(420px, calc(100vw - 24px)); }

.sheet::backdrop { background: rgb(0 0 0 / 0.5); }

.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.sheet-section {
  display: grid;
  gap: 8px;
  justify-items: start;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.hint { margin: 0; color: var(--muted); font-size: 0.9375rem; }

.lightbox {
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  padding: 0;
  background: #000;
  border: 0;
  cursor: zoom-out;
}

.lightbox::backdrop { background: #000; }

.lightbox img { display: block; width: 100%; height: 100%; object-fit: contain; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 20;
  width: max-content;
  max-width: calc(100vw - 32px);
  transform: translateX(-50%);
  padding: 10px 16px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 8px;
}

[hidden] { display: none !important; }
