*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:       #0891B2;
  --primary-hover: #0E7490;
  --bg:            #F5F5F0;
  --card:          #FFFFFF;
  --card-border:   #EDEEEF;
  --muted:         #F0F4F5;
  --muted-fg:      #6B7280;
  --fg:            #1F2937;
  --header-bg:     #ECFEFF;
  --destructive:   #DC2626;
  --radius:        20px;
  --shadow:        0 2px 12px rgba(31,41,55,0.07);
  --shadow-hover:  0 8px 28px rgba(8,145,178,0.15);
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
}

/* ── Header ── */
header {
  background: var(--header-bg);
  border-bottom: 1px solid #A5F3FC;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-top {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 24px 12px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.logo-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.logo-icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}
h1 {
  font-family: "Righteous", sans-serif;
  font-size: 1.4rem;
  font-weight: 400;
  color: #164E63;
  letter-spacing: 0.02em;
}

/* ── Stats bar ── */
.stats-bar {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-left: auto;
}
.stat {
  font-size: 0.77rem;
  color: #4B7A88;
  display: flex;
  align-items: center;
  gap: 5px;
}
.stat strong { color: #164E63; font-weight: 600; }
.stat-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
}
.dot-is24     { background: #67E8F9; }
.dot-immowelt { background: #A78BFA; }
.dot-kleinanz { background: #6EE7B7; }
.dot-applied  { background: #86EFAC; }

/* ── Status tabs ── */
.status-tabs {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  gap: 0;
}
.status-tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  flex-shrink: 0;
  padding: 10px 18px;
  border: none;
  background: none;
  font-family: "Inter", sans-serif;
  font-size: 0.83rem;
  font-weight: 500;
  color: #4B7A88;
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: color 0.15s;
  white-space: nowrap;
}
.tab-btn::after {
  content: "";
  position: absolute;
  bottom: -1px; left: 12px; right: 12px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: #0891B2;
  transform: scaleX(0);
  transition: transform 0.18s ease;
}
.tab-btn:hover { color: #0E7490; }
.tab-btn.active { color: #164E63; font-weight: 700; }
.tab-btn.active::after { transform: scaleX(1); }

.tab-count {
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  background: #A5F3FC;
  color: #164E63;
  transition: background 0.15s, color 0.15s;
}
.tab-btn.active .tab-count {
  background: #0891B2;
  color: #fff;
}

/* ── Source strip ── */
.source-strip {
  background: #fff;
  border-bottom: 1px solid var(--card-border);
}
.source-strip-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.source-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted-fg);
  padding-right: 6px;
}
.source-chip {
  padding: 3px 11px;
  border-radius: 999px;
  border: 1.5px solid transparent;
  font-family: "Inter", sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 5px;
}
.chip-all {
  background: var(--muted);
  color: var(--muted-fg);
  border-color: var(--card-border);
}
.chip-all.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.chip-is24 { background: #EFF6FF; color: #1565c0; border-color: #BFDBFE; }
.chip-is24.active { background: #1565c0; color: #fff; border-color: #1565c0; }
.chip-immowelt { background: #FAF5FF; color: #6a1b9a; border-color: #E9D5FF; }
.chip-immowelt.active { background: #6a1b9a; color: #fff; border-color: #6a1b9a; }
.chip-kleinanz { background: #ECFDF5; color: #065F46; border-color: #A7F3D0; }
.chip-kleinanz.active { background: #059669; color: #fff; border-color: #059669; }

/* ── Brand logo icons ── */
img.brand-logo {
  width: 16px !important;
  height: 16px !important;
  min-width: 16px;
  max-width: 16px;
  flex-shrink: 0;
  border-radius: 4px;
  object-fit: cover;
  display: inline-block !important;
  vertical-align: middle;
}

/* ── Grid ── */
.listings-grid {
  max-width: 1200px;
  margin: 24px auto 60px;
  padding: 0 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}
.loading, .empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px;
  color: var(--muted-fg);
  font-size: 1rem;
}

/* ── Card ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--card-border);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.2s, transform 0.2s;
}
.card:hover {
  box-shadow: var(--shadow-hover);
  transform: scale(1.015);
}
.card.is-skipped { opacity: 0.65; }
.card.is-skipped .card-title { text-decoration: line-through; color: var(--muted-fg); }

/* Offline — visibly "dead", but View Ad link stays usable */
.card.is-offline .carousel img:not(.brand-logo) {
  filter: grayscale(0.8) opacity(0.55);
}
.card.is-offline .card-title {
  text-decoration: line-through;
  color: var(--muted-fg);
}
.card.is-offline .card-meta,
.card.is-offline .card-district {
  color: #9CA3AF;
}
.card.is-offline .meta-item strong {
  color: #9CA3AF;
}

/* ── Photo carousel ── */
.carousel {
  position: relative;
  aspect-ratio: 4/3;
  background: var(--muted);
  overflow: hidden;
}
.carousel img:not(.brand-logo) {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}
.carousel img.active { display: block; }
.carousel-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.35);
  color: #fff;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}
.carousel:hover .carousel-btn { opacity: 1; }
.carousel-btn.prev { left: 8px; }
.carousel-btn.next { right: 8px; }
.carousel-dots {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 5px;
}
.carousel-dots span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.6);
}
.carousel-dots span.active { background: #fff; }
.no-photo {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.5rem; color: #b2d8d4;
}
.source-ribbon {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 5px 11px 5px 7px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  z-index: 2;
}
.source-ribbon .brand-logo {
  border-radius: 3px;
}
.source-ribbon span {
  line-height: 1;
}
.ribbon-is24 {
  background: rgba(239, 246, 255, 0.92);
  color: #1565c0;
  border-color: rgba(191, 219, 254, 0.9);
}
.ribbon-immowelt {
  background: rgba(250, 245, 255, 0.92);
  color: #6a1b9a;
  border-color: rgba(233, 213, 255, 0.9);
}
.ribbon-kleinanz {
  background: rgba(236, 253, 245, 0.92);
  color: #065F46;
  border-color: rgba(167, 243, 208, 0.9);
}

/* ── Card body ── */
.card-body { padding: 16px; flex: 1; display: flex; flex-direction: column; gap: 10px; }

.card-header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card-header-right { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex-shrink: 0; }

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--fg);
}

/* ── Status badges ── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge-pending_review { background: #CFFAFE; color: #164E63; border: 1px solid #A5F3FC; }
.badge-applied        { background: #D1FAE5; color: #065F46; border: 1px solid #6EE7B7; }
.badge-skipped        { background: #F1F5F9; color: #64748B; border: 1px solid #E2E8F0; }
.badge-offline        { background: #F3F4F6; color: #6B7280; border: 1px dashed #9CA3AF; }
.badge-error          { background: #FEE2E2; color: #991B1B; border: 1px solid #FECACA; }
.badge-captcha_blocked { background: #FEF3C7; color: #92400E; border: 1px solid #FDE68A; }

/* ── Meta ── */
.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 0.82rem;
  color: var(--muted-fg);
}
.meta-item { display: flex; align-items: center; gap: 4px; font-weight: 500; }
.meta-item strong { color: var(--fg); font-weight: 600; }

.card-district { font-size: 0.78rem; color: var(--muted-fg); }

/* ── Card footer ── */
.card-footer { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 8px; }

.btn-ad {
  display: block;
  text-align: center;
  padding: 9px;
  background: var(--fg);
  color: #fff;
  border-radius: 10px;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.15s;
}
.btn-ad:hover { background: #111827; }

.toggle-msg {
  background: none;
  border: 1.5px solid var(--card-border);
  border-radius: 10px;
  padding: 7px;
  font-size: 0.82rem;
  color: var(--muted-fg);
  cursor: pointer;
  width: 100%;
  font-family: "Inter", sans-serif;
  transition: border-color 0.15s, color 0.15s;
}
.toggle-msg:hover { border-color: var(--primary); color: var(--primary); }

.message-box {
  display: none;
  background: var(--muted);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 12px;
  font-size: 0.82rem;
  line-height: 1.65;
  color: var(--fg);
  white-space: pre-wrap;
}
.message-box.open { display: block; }

/* ── Action buttons ── */
.action-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.btn-apply, .btn-skip {
  padding: 10px;
  border-radius: 10px;
  border: none;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  font-family: "Inter", sans-serif;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: opacity 0.15s;
}
.btn-apply:disabled, .btn-skip:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-apply {
  background: linear-gradient(135deg, #0891B2, #22D3EE);
  color: #fff;
  box-shadow: 0 4px 12px rgba(8,145,178,0.30);
}
.btn-apply:hover:not(:disabled) { opacity: 0.88; }

.btn-skip {
  background: #fff;
  color: var(--muted-fg);
  border: 1.5px solid var(--card-border);
}
.btn-skip:hover:not(:disabled) { background: var(--muted); border-color: var(--primary); }

/* ── Spinner ── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

/* ── Applied at ── */
.applied-at { font-size: 0.73rem; color: #aaa; text-align: right; }

/* ── Last-run pill ── */
.last-run-pill {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--card-border);
  color: #164E63;
  font: 500 0.78rem "Inter", sans-serif;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.last-run-pill:hover { border-color: var(--primary); background: var(--muted); }
.last-run-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #22D3EE;
  box-shadow: 0 0 0 3px rgba(34,211,238,0.18);
}
.last-run-pill.has-error .last-run-dot {
  background: #F59E0B;
  box-shadow: 0 0 0 3px rgba(245,158,11,0.18);
}

/* ── Runs modal ── */
body.modal-open { overflow: hidden; }

.runs-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.runs-modal[hidden] { display: none; }
.runs-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(31,41,55,0.45);
  backdrop-filter: blur(2px);
}
.runs-modal-panel {
  position: relative;
  width: min(640px, 100%);
  max-height: calc(100vh - 48px);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(8,145,178,0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.runs-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--card-border);
  background: var(--header-bg);
}
.runs-modal-header h2 {
  font: 600 1rem "Inter", sans-serif;
  color: #164E63;
}
.runs-modal-close {
  background: transparent;
  border: none;
  font-size: 1rem;
  color: var(--muted-fg);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.runs-modal-close:hover { background: var(--muted); color: var(--fg); }
.runs-modal-body {
  overflow-y: auto;
  padding: 8px 0;
}

.runs-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.run-row {
  padding: 14px 20px;
  border-bottom: 1px solid var(--card-border);
}
.run-row:last-child { border-bottom: none; }
.run-row-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.run-when-abs { font-size: 0.85rem; color: var(--fg); font-weight: 500; }
.run-when-rel { font-size: 0.72rem; color: var(--muted-fg); margin-top: 2px; }
.run-totals {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted-fg);
}
.run-new strong { color: #164E63; font-size: 0.95rem; }
.run-sep { opacity: 0.5; }
.run-offline { color: #B45309; }
.run-breakdown {
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--muted-fg);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.run-label { color: #164E63; font-weight: 500; margin-right: 4px; }
.run-error {
  margin-top: 6px;
  padding: 6px 10px;
  background: #FEF3C7;
  color: #92400E;
  font-size: 0.75rem;
  border-radius: 8px;
}
