:root {
  --primary: #2f6f4f;
  --primary-dark: #204f38;
  --primary-soft: #e3efe8;
  --bg: #f4f6f5;
  --card-bg: #ffffff;
  --text: #1c2620;
  --muted: #6b7a72;
  --danger: #b3261e;
  --border: #dde3e0;
  --warn-bg: #fff4d6;
  --warn-text: #6b4e00;
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #5fb38a;
    --primary-dark: #4a9873;
    --primary-soft: #1f3a2d;
    --bg: #111614;
    --card-bg: #1b2320;
    --text: #e4ebe7;
    --muted: #93a39a;
    --danger: #ff8a80;
    --border: #2c3833;
    --warn-bg: #3a3214;
    --warn-text: #f3dc8d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

body.app { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }

.topbar {
  background: var(--primary-dark);
  color: white;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 5;
}

@media (prefers-color-scheme: dark) { .topbar { background: #18352a; } }

.topbar h1 { font-size: 1.15rem; margin: 0; }
.whoami { font-size: 0.85rem; opacity: 0.85; }

.topbar-actions { display: flex; align-items: center; gap: 12px; font-size: 0.9rem; }
.topbar-actions a { color: white; text-decoration: underline; }
.topbar button {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.4);
  padding: 6px 10px;
}

.hidden { display: none !important; }

.banner {
  background: var(--warn-bg);
  color: var(--warn-text);
  padding: 8px 16px;
  font-size: 0.9rem;
  text-align: center;
}

.content {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.view { display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}

.card h2 { margin-top: 0; font-size: 1.05rem; }
.card h3 { font-size: 0.95rem; margin-bottom: 6px; margin-top: 16px; }

button, input[type="submit"] {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.95rem;
  cursor: pointer;
  min-height: 42px;
  font-family: inherit;
}
@media (prefers-color-scheme: dark) { button, input[type="submit"] { color: #0d1a14; } }

button:hover { background: var(--primary-dark); }
button:disabled { opacity: 0.5; cursor: default; }
button.danger { background: var(--danger); color: white; }
button.secondary {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--border);
}
button.secondary:hover { background: var(--primary-soft); }
button.danger-text { color: var(--danger); }

.icon-btn {
  background: transparent;
  color: var(--muted);
  min-height: 36px;
  min-width: 36px;
  padding: 4px 8px;
  font-size: 1rem;
}
.icon-btn:hover { background: var(--primary-soft); color: var(--danger); }

input[type="text"],
input[type="password"],
input[type="url"],
input[type="file"],
input[type="date"],
input[type="time"],
textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--text);
  min-height: 42px;
}

textarea { min-height: 80px; resize: vertical; }

label { display: block; font-size: 0.9rem; color: var(--muted); }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1; min-width: 120px; }
.stack, .stack-form { display: flex; flex-direction: column; gap: 8px; }
.stack-form .error, .stack-form .msg { margin: 0; }

form.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
form.inline-form input { flex: 1; min-width: 160px; margin: 0; }
form.inline-form label { display: inline-flex; align-items: center; gap: 6px; color: var(--text); }
form.inline-form input[type="checkbox"] { flex: none; min-width: 0; width: 18px; height: 18px; }

.error { color: var(--danger); min-height: 1.2em; font-size: 0.9rem; margin: 6px 0 0; }
.msg { color: var(--muted); font-size: 0.9rem; min-height: 1.2em; }
.muted { color: var(--muted); font-size: 0.9rem; }
.small { font-size: 0.8rem; }
.center { text-align: center; }

/* Termine */
.day-groups { display: flex; flex-direction: column; gap: 10px; }
.day { padding: 10px 14px; }
.day-title { margin: 0 0 6px !important; font-size: 0.85rem !important; color: var(--primary); text-transform: none; }
.event { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--border); }
.day-title + .event { border-top: none; }
.event-icon { font-size: 1.3rem; width: 1.6rem; text-align: center; }
.event-body { flex: 1; min-width: 0; }
.event-title { word-break: break-word; }

/* Listen */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip {
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  min-height: 36px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chip:hover { background: var(--primary-soft); }
.chip.active { background: var(--primary); color: white; border-color: var(--primary); }
@media (prefers-color-scheme: dark) { .chip.active { color: #0d1a14; } }
.chip.add { color: var(--primary); border-style: dashed; }
.badge {
  background: rgba(0, 0, 0, 0.12);
  border-radius: 999px;
  padding: 0 7px;
  font-size: 0.75rem;
  line-height: 1.4;
}
.items { list-style: none; padding: 0; margin: 12px 0; }
.item { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--border); padding: 4px 0; }
.item:first-child { border-top: none; }
.item-label { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; color: var(--text); font-size: 1rem; padding: 6px 0; cursor: pointer; }
.item-label span { word-break: break-word; }
.item input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--primary); flex: none; }
.item.done .item-label span { text-decoration: line-through; color: var(--muted); }
.item-by { white-space: nowrap; }
.list-actions { justify-content: flex-start; }
.list-actions button { min-height: 36px; padding: 6px 10px; font-size: 0.85rem; }

/* Pinnwand */
.notes-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.note { position: relative; padding-right: 44px; }
.note-meta { font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; }
.note-text { white-space: pre-wrap; word-break: break-word; }
.note-delete { position: absolute; top: 8px; right: 6px; }

/* Tab-Leiste */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 10;
}
.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.75rem;
}
.tabbar a span { font-size: 1.3rem; filter: grayscale(1); opacity: 0.7; }
.tabbar a.active { color: var(--primary); font-weight: 600; }
.tabbar a.active span { filter: none; opacity: 1; }

/* Overlay (Passwort festlegen) */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

/* Login */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
}
.auth-card h1 { text-align: center; color: var(--primary); margin-top: 0; }
.auth-card h2 { margin-top: 0; }
.auth-card label input { margin: 4px 0 12px; }
.auth-card form > button { width: 100%; }

/* Verwaltung */
.admin-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; font-size: 0.9rem; }
.admin-table th, .admin-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.admin-table td button { margin: 0 6px 6px 0; padding: 4px 8px; font-size: 0.8rem; min-height: 30px; }
.warn { background: var(--warn-bg); color: var(--warn-text); border-radius: 8px; padding: 10px 12px; font-size: 0.9rem; }
.ok { color: var(--primary); }
.admin .content { max-width: 960px; }
.table-wrap { overflow-x: auto; }
