:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1b1e23;
  --muted: #6b7280;
  --border: #e3e5e9;
  --accent: #2563eb;
  --accent-contrast: #ffffff;
  --new: #16a34a;
  --sponsored: #b45309;
  --ka: #6b21a8;
  --ebay: #0064d2;
  --willhaben: #e8590c;
  --good-price: #059669;
  --repost: #6b7280;
  --favorite: #eab308;
  --dismiss: #dc2626;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2026;
    --text: #eceef1;
    --muted: #9aa1ac;
    --border: #2c3038;
    --accent: #3b82f6;
    --accent-contrast: #0b0d10;
    --new: #34d399;
    --sponsored: #fbbf24;
    --ka: #c084fc;
    --ebay: #6cb2ff;
    --willhaben: #ff922b;
    --good-price: #34d399;
    --repost: #9aa1ac;
    --favorite: #fbbf24;
    --dismiss: #f87171;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  padding: 24px 20px 8px;
  max-width: 900px;
  margin: 0 auto;
}

h1 { margin: 0 0 4px; font-size: 1.6rem; }
.subtitle { margin: 0; color: var(--muted); font-size: 0.9rem; }

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 12px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
}

.panel h2 { margin: 0 0 12px; font-size: 1.05rem; }

#search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

#search-form input[type="text"] { flex: 1 1 220px; }
#search-form input[type="number"] { width: 130px; }

input, button {
  font-family: inherit;
  font-size: 0.9rem;
}

input[type="text"], input[type="number"] {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

label { color: var(--muted); font-size: 0.85rem; display: flex; align-items: center; gap: 4px; }

button {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-contrast);
  cursor: pointer;
  font-weight: 600;
}
button:hover { opacity: 0.9; }
button.secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  font-weight: 500;
  padding: 4px 10px;
  font-size: 0.8rem;
}

.chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 6px 6px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  background: var(--bg);
}
.chip.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.chip .del { color: var(--muted); padding: 2px 8px; border-radius: 999px; }
.chip .del:hover { background: var(--border); }
.chip.inactive { opacity: 0.5; }

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
}
.results-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; font-size: 0.8rem; }
.muted { color: var(--muted); font-weight: 400; font-size: 0.85rem; }

#listings { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

.listing {
  display: flex;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.1s ease;
}
.listing:hover { border-color: var(--accent); }

.listing-main { flex: 1; min-width: 0; }
.listing-title { font-weight: 600; margin: 0 0 4px; overflow-wrap: anywhere; }
.listing-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 0.8rem; color: var(--muted); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.badge.new { background: var(--new); color: #06210f; }
.badge.sponsored { background: var(--sponsored); color: #2b1600; }
.badge.good-price { background: var(--good-price); color: #032018; }
.badge.repost { background: var(--repost); color: white; text-transform: none; }
.badge.source-kleinanzeigen { background: var(--ka); color: white; }
.badge.source-ebay { background: var(--ebay); color: white; }
.badge.source-willhaben { background: var(--willhaben); color: white; }

.listing-price-box { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; align-self: center; white-space: nowrap; }
.listing-price { font-weight: 700; font-size: 1rem; }
.price-change { font-size: 0.72rem; font-weight: 600; }
.price-change.cheaper { color: var(--good-price); }
.price-change.pricier { color: var(--dismiss); }

.listing.is-seen { opacity: 0.55; }

.listing-link {
  display: flex;
  gap: 12px;
  flex: 1;
  min-width: 0;
  text-decoration: none;
  color: var(--text);
}

.listing-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  justify-content: center;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  padding: 2px 8px;
  font-size: 0.85rem;
  line-height: 1.4;
  cursor: pointer;
  font-weight: 400;
}
.icon-btn:hover { border-color: var(--accent); color: var(--text); opacity: 1; }
.icon-btn.is-favorite { color: var(--favorite); border-color: var(--favorite); }
.icon-btn.is-seen-btn { color: var(--accent); border-color: var(--accent); }
.icon-btn.is-dismiss-btn { color: var(--dismiss); border-color: var(--dismiss); }

.empty-state { color: var(--muted); padding: 24px; text-align: center; }
