:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #667085;
  --border: #e3e6ea;
  --primary: #1a7f4e;
  --primary-hover: #156b41;
  --primary-soft: #e5f4ec;
  --new: #d97706;
  --new-soft: #fef3e2;
  --danger: #b42318;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101418;
    --surface: #1a2027;
    --text: #e6e9ec;
    --muted: #8b96a3;
    --border: #2a323c;
    --primary: #2ea36c;
    --primary-hover: #38b97c;
    --primary-soft: #17301f;
    --new: #f59e0b;
    --new-soft: #33250e;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px 8px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
h1 { font-size: 20px; margin: 0; }
.subtitle { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 6px; }
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Umschalt-Leiste für die Quellen-Bubbles (nur mobil sichtbar) */
.source-toggle {
  display: none;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 8px;
  padding: 6px 2px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.source-toggle .chevron { margin-left: auto; transition: transform .3s ease; color: var(--muted); }
body.sources-expanded .source-toggle .chevron { transform: rotate(180deg); }
#source-summary { font-weight: 400; }

/* Mobile-Leiste mit Filter-Button (nur mobil sichtbar) */
.mobile-bar { display: none; }
.filter-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin-left: 6px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

/* Drawer-Kopf + Backdrop (nur mobil aktiv) */
.drawer-head { display: none; }
.drawer-backdrop { display: none; }

.source-status { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.source-chip {
  font-size: 12px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: default;
}
.source-chip .cnt { font-weight: 600; color: var(--text); }
.source-chip.err { border-color: var(--danger); color: var(--danger); }

main {
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 20px;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

aside {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  height: fit-content;
  position: sticky;
  top: 96px;
}

.filter-group { margin-bottom: 14px; }
.filter-group > label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin-bottom: 6px;
}
input, select, textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.row2 { display: flex; gap: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  cursor: pointer;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-block { width: 100%; justify-content: center; }
.btn-icon { padding: 7px 10px; }
.btn:disabled { opacity: .55; cursor: wait; }

.hint { font-size: 12px; color: var(--muted); }
.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-size: 14px !important;
  font-weight: 400 !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  color: var(--text) !important;
  cursor: pointer;
}
.checkbox-label input { width: auto; }
.muted { color: var(--muted); font-size: 13px; }
.spacer { flex: 1; }

.pill {
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 700;
}
.pill-new { background: var(--new-soft); color: var(--new); }

#result-count { margin-bottom: 10px; }
#cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.card.is-applied { outline: 2px solid var(--primary); outline-offset: -2px; }
.card-img { height: 150px; background: var(--bg); }
.card-img:empty, .card-img.no-img { display: none; }
.card-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 7px; flex: 1; }
.card-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.card-date { margin-left: auto; font-size: 12px; }

.badge {
  font-size: 11px;
  font-weight: 700;
  border-radius: 5px;
  padding: 2px 7px;
  letter-spacing: .02em;
}
.badge-source { background: var(--primary-soft); color: var(--primary); }
.badge-new { background: var(--new-soft); color: var(--new); }
.badge-inactive { background: var(--border); color: var(--muted); }
.badge-reserved { background: var(--border); color: var(--danger); }
.badge-outdated { background: var(--border); color: var(--danger); }
.badge-longtime { background: var(--border); color: var(--muted); cursor: help; }
.card.is-reserved, .card.is-outdated { opacity: .75; }
.card.is-reserved .btn-apply, .card.is-outdated .btn-apply { background: var(--surface); border-color: var(--border); color: var(--muted); font-weight: 400; }
.badge-applied { background: var(--primary); color: #fff; }

.card-title { margin: 0; font-size: 16px; line-height: 1.3; }
.card-facts { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 14px; }
.card-facts b { font-weight: 600; }
.card-facts .rent { color: var(--primary); font-weight: 700; }

.card-notes { font-size: 13px; padding: 5px 9px; }
.card-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 4px; }
.btn-apply { flex: 1; justify-content: center; }
.btn-fav.on { color: #eab308; border-color: #eab308; }
.btn-applied.on { color: var(--primary); border-color: var(--primary); }

.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
  font-size: 15px;
}

dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  max-width: 560px;
  width: calc(100vw - 40px);
  padding: 22px;
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin: 0 0 4px; font-size: 18px; }
#profile-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.profile-label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); }
.profile-label input, .profile-label textarea { margin-top: 4px; font-weight: 400; }
.profile-field { display: flex; align-items: flex-end; gap: 6px; }
.profile-field .copy {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  padding: 7px 9px;
  cursor: pointer;
  color: var(--text);
}
.profile-field .copy:active { background: var(--primary-soft); }
.dialog-actions { display: flex; gap: 8px; margin-top: 14px; }

.users-table { width: 100%; border-collapse: collapse; margin: 14px 0; }
.users-table th { text-align: left; font-size: 12px; text-transform: uppercase; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--border); }
.users-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); }
.users-table select { width: auto; }
.u-actions { text-align: right; white-space: nowrap; }
.u-actions .btn[disabled] { opacity: .35; cursor: not-allowed; }
.users-add-title { font-size: 14px; margin: 16px 0 8px; }
.user-add { display: flex; gap: 8px; flex-wrap: wrap; }
.user-add input { flex: 1; min-width: 130px; }
.user-add select { width: auto; }
.pw-change { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.pw-change summary { cursor: pointer; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.pw-change .btn { margin-top: 8px; }

#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  z-index: 100;
  transition: opacity .3s;
}

/* ------------------------------------------------------------------ mobile */
@media (max-width: 800px) {
  /* Kompakter Header */
  header { padding: 10px 14px 6px; }
  h1 { font-size: 17px; }
  .subtitle, #last-update, #whoami { display: none; }
  .header-actions { gap: 6px; }
  .header-actions .btn-label { display: none; }   /* Buttons nur mit Icon */
  .header-actions .btn { padding: 7px 10px; }

  /* Quellen-Bubbles einklappbar (slide up/down) */
  .source-toggle { display: flex; }
  .source-status {
    max-height: 0;
    margin-top: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height .3s ease, opacity .25s ease, margin-top .3s ease;
  }
  body.sources-expanded .source-status {
    max-height: 60vh;
    overflow-y: auto;
    margin-top: 8px;
    opacity: 1;
  }

  /* Filter-Leiste über der Liste */
  .mobile-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 16px 0;
    max-width: 1400px;
    margin: 0 auto;
  }

  /* Sidebar wird zum von links einfahrenden Drawer */
  main { grid-template-columns: 1fr; padding: 12px 16px 20px; gap: 12px; }
  #filters {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 84%;
    max-width: 330px;
    z-index: 50;
    border-radius: 0;
    border-width: 0 1px 0 0;
    transform: translateX(-100%);
    transition: transform .28s ease;
    overflow-y: auto;
    box-shadow: 2px 0 22px rgba(0, 0, 0, .35);
  }
  body.drawer-open #filters { transform: translateX(0); }
  .drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(0, 0, 0, .45);
    opacity: 0;
    pointer-events: none;
    transition: opacity .28s ease;
  }
  body.drawer-open .drawer-backdrop { display: block; opacity: 1; pointer-events: auto; }
  .drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: -16px -16px 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
  }
  .drawer-head strong { font-size: 16px; }
  /* Karten volle Breite, angenehm grosse Tap-Ziele */
  #cards { grid-template-columns: 1fr; }
  #result-count { display: none; }   /* Zähler steht schon in der Filter-Leiste */
  .btn { padding: 9px 14px; }
  .chip { padding: 6px 13px; font-size: 14px; }
}
