:root {
  --bg: #f5f2ec;
  --surface: #fffdf9;
  --surface-2: #efebe3;
  --text: #1d2420;
  --muted: #6b716c;
  --line: #e2ddd3;
  --accent: #1f5c4a;
  --accent-text: #f5efe3;
  --accent-soft: #dcebe4;
  --danger: #b3412e;
  --shadow: 0 1px 2px rgb(30 30 20 / .05), 0 4px 16px rgb(30 30 20 / .05);
  --radius: 14px;
  --immoscout: #2a8a78;
  --kleinanzeigen: #4d7a14;
  --immowelt: #c8551b;
  --wggesucht: #3f6fb0;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141816;
    --surface: #1c211f;
    --surface-2: #242a27;
    --text: #e8e6e1;
    --muted: #9aa19c;
    --line: #2f3632;
    --accent: #6fbf9f;
    --accent-text: #0f1a15;
    --accent-soft: #1f3a2f;
    --danger: #e0806c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; }
code { font-size: .85em; background: var(--surface-2); padding: .1em .35em; border-radius: 5px; word-break: break-all; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 64px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; text-decoration: none; font-size: 1.05rem; }
.brand svg, .login-logo { width: 28px; height: 28px; }
.brand svg rect, .login-logo rect { fill: var(--accent); }
.brand svg path, .login-logo path { fill: var(--accent-text); }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
  text-decoration: none; padding: 6px 12px; border-radius: 999px; color: var(--muted); font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
}
.topbar nav a:hover { color: var(--text); background: var(--surface-2); }
.topbar nav a[aria-current] { color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
.topbar-actions { display: flex; gap: 6px; align-items: center; }
.pill { background: var(--accent); color: var(--accent-text); border-radius: 999px; font-size: .75rem; padding: 0 7px; font-weight: 600; }

/* Buttons */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; padding: 7px 14px; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { border-color: var(--accent); filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn-small { padding: 4px 10px; font-size: .85rem; border-radius: 8px; }
.btn-icon { padding: 7px 11px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.dot-busy { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* Cards & forms */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.form-card, section.card { padding: 20px; margin-bottom: 16px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); font-weight: 500; margin-bottom: 12px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; line-height: 1.5; }
.fields { display: grid; gap: 0 16px; }
.fields-2 { grid-template-columns: repeat(2, 1fr); }
.fields-4 { grid-template-columns: repeat(4, 1fr); }
label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); align-self: end; }
label.check input { width: auto; }
.inline-form { display: grid; grid-template-columns: 1fr 2fr auto; gap: 8px; margin: 12px 0; }
.hints { font-size: .85rem; padding-left: 18px; margin: 8px 0 0; }
.hints li { margin-bottom: 4px; }
.notice { background: var(--accent-soft); padding: 10px 14px; border-radius: 10px; margin: 0 0 16px; }
.sticky-save { position: sticky; bottom: 16px; display: flex; justify-content: flex-end; }
.sticky-save .btn { box-shadow: 0 6px 20px rgb(0 0 0 / .15); padding: 10px 22px; }

/* Toolbar & tabs */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; overflow-x: auto; max-width: 100%; }
.tabs a { text-decoration: none; padding: 6px 12px; border-radius: 9px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.tabs a[aria-selected] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tabs .count { font-size: .8rem; opacity: .7; margin-left: 2px; }
.platform-filter select { width: auto; background: var(--surface); }

/* Listing grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; align-items: start; }
.listing { overflow: hidden; display: flex; flex-direction: column; transition: opacity .25s, transform .25s; }
.listing.leaving { opacity: 0; transform: scale(.97); }
.thumb { position: relative; display: block; aspect-ratio: 16 / 9; background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.badge {
  display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .02em;
  padding: 2px 8px; border-radius: 6px; color: #fff; background: var(--muted);
}
.thumb .badge { position: absolute; top: 10px; left: 10px; }
.badge-immoscout { background: var(--immoscout); }
.badge-kleinanzeigen { background: var(--kleinanzeigen); }
.badge-immowelt { background: var(--immowelt); }
.badge-wggesucht { background: var(--wggesucht); }
.listing .body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.listing h3 { font-size: 1rem; margin: 0; }
.listing h3 a { text-decoration: none; }
.listing h3 a:hover { text-decoration: underline; }
.meta { display: flex; flex-direction: column; gap: 1px; font-size: .82rem; }
.meta .when { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.facts { display: grid; grid-template-columns: repeat(4, 1fr); margin: 0; background: var(--bg); border-radius: 10px; padding: 8px 4px; }
.facts div { text-align: center; }
.facts dt { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.facts dd { margin: 0; font-weight: 650; font-variant-numeric: tabular-nums; }
.commute { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: .84rem; }
.commute li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }
.commute .target { font-weight: 650; min-width: 52px; }
.commute .km { color: var(--muted); font-variant-numeric: tabular-nums; }
.commute .mode b { font-size: .7rem; font-weight: 600; color: var(--muted); letter-spacing: .03em; margin-right: 2px; }
.commute small { color: var(--muted); }
.target-row { grid-template-columns: 1fr 3fr auto; align-items: end; }
.target-state { font-size: .85rem; padding-bottom: 22px; min-width: 100px; }
.target-state .ok { color: var(--accent); }
.platform-filter { display: flex; gap: 8px; }
.reason { font-size: .82rem; color: var(--danger); margin: 0; }
.tag { font-size: .72rem; background: var(--accent-soft); color: var(--text); padding: 1px 7px; border-radius: 6px; margin-left: 6px; font-weight: 500; }

.draft summary { cursor: pointer; font-weight: 600; font-size: .9rem; padding: 2px 0; }
.draft textarea { margin-top: 8px; font-size: .88rem; }
.draft-actions { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.draft-actions .saved { font-size: .8rem; }
.actions { display: flex; gap: 6px; }
.actions .grow { flex: 1; justify-content: center; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.actions .btn { padding-inline: 12px; }
.listing[data-status="favorite"] [data-status-set="favorite"] { color: #c99a06; border-color: #c99a06; }
.busy { opacity: .6; pointer-events: none; }
.empty { padding: 40px 24px; text-align: center; }

/* Searches table */
.table-wrap { overflow-x: auto; }
table.searches { width: 100%; border-collapse: collapse; }
.searches td { padding: 12px 8px; border-top: 1px solid var(--line); vertical-align: middle; }
.searches tr:first-child td { border-top: 0; }
.searches .name { max-width: 460px; }
.searches .url { display: block; font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.searches .status { font-size: .85rem; white-space: nowrap; }
.searches .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.searches tr.inactive { opacity: .55; }

/* Login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(360px, 100%); padding: 32px 28px; display: flex; flex-direction: column; }
.login-logo { width: 44px; height: 44px; margin-bottom: 12px; }
.login h1 { font-size: 1.5rem; margin: 0; }
.login p { margin: 0 0 20px; }
.login .btn { justify-content: center; margin-top: 4px; }

/* Mobile */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; }
  .topbar nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .topbar-actions { margin-left: auto; }
  .run-label { display: none; }
  .grid { grid-template-columns: 1fr; }
  .fields-2, .fields-4, .inline-form, .target-row { grid-template-columns: 1fr; }
  .target-state { padding-bottom: 8px; }
  .platform-filter { flex-wrap: wrap; }
  .searches td { display: block; border: 0; padding: 4px 0; }
  .searches tr { display: block; border-top: 1px solid var(--line); padding: 10px 0; }
  .searches .row-actions { justify-content: flex-start; }
  .searches .name { max-width: calc(100vw - 72px); }
}
