:root {
  --bg: #f4f6f8;
  --card: #fff;
  --text: #1a1f2c;
  --muted: #667085;
  --border: #e4e7ec;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --badge: #dc2626;
  --chip: #eef2ff;
  --chip-active: #1d4ed8;
  --out: #b91c1c;
  --out-hover: #991b1b;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.brand h1 { margin: 0; font-size: 1.35rem; }
.sub { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.9rem; }
.brand .path { margin: 0.25rem 0 0; }
.brand .path code {
  font-size: 0.78rem;
  color: var(--muted);
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.15rem 0.45rem;
}
.actions { display: flex; align-items: center; gap: 0.75rem; }

.badge {
  background: var(--badge);
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
}
.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
.btn:hover { background: #f8fafc; }
.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn.primary:hover { background: var(--primary-hover); }
.btn:disabled { opacity: 0.6; cursor: wait; }

.panel, .filters, main {
  max-width: 1500px;
  margin: 1rem auto;
  padding: 0 1.25rem;
}
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
}
details summary { cursor: pointer; font-weight: 600; }
.source-urls { list-style: none; padding: 0.75rem 0 0; margin: 0; }
.source-urls li { margin-bottom: 0.75rem; }
.full-url {
  display: block;
  margin-top: 0.25rem;
  padding: 0.5rem 0.65rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-all;
  font-size: 0.8rem;
}
.last-runs { margin-top: 0.75rem; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.run-pill {
  background: #f1f5f9;
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.muted { color: var(--muted); }
.scrape-status {
  margin-top: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  font-size: 0.9rem;
  white-space: pre-wrap;
}
.scrape-status.error {
  background: #fef2f2;
  border-color: #fecaca;
}

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; }
.filter-label { font-weight: 600; margin-right: 0.25rem; }
.chip {
  display: inline-block;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: var(--chip);
  color: #312e81;
  font-size: 0.9rem;
  text-decoration: none;
  border: 1px solid transparent;
}
.chip:hover { text-decoration: none; border-color: #c7d2fe; }
.chip.active {
  background: var(--chip-active);
  color: #fff;
}
.chip-count {
  display: inline-block;
  margin-left: 0.2rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  font-size: 0.78em;
  font-weight: 700;
  background: rgba(49, 46, 129, 0.12);
  color: inherit;
  min-width: 1.2em;
  text-align: center;
}
.chip.active .chip-count {
  background: rgba(255, 255, 255, 0.22);
}
.hint {
  width: 100%;
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
}
table.listings {
  width: 100%;
  border-collapse: collapse;
  min-width: 1100px;
}
table.listings th, table.listings td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  text-align: left;
  font-size: 0.92rem;
}
table.listings th {
  background: #f8fafc;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--muted);
}
.col-img img.gallery-thumb {
  width: 192px;
  height: 144px;
  object-fit: cover;
  border-radius: 8px;
  background: #e5e7eb;
}
.no-img { color: var(--muted); }
.col-title .meta { color: var(--muted); font-size: 0.8rem; margin-top: 0.15rem; }
.empty { text-align: center; color: var(--muted); padding: 2rem !important; }

.col-status {
  width: 11rem;
  min-width: 10.5rem;
  vertical-align: top;
}
.status-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  min-height: 2.5rem;
}
.status-cell.busy { opacity: 0.55; pointer-events: none; }
.status-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  line-height: 1.2;
}
.status-btn.out-btn {
  background: var(--out);
  border-color: var(--out);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.4rem 0.75rem;
  letter-spacing: 0.03em;
}
.status-btn.out-btn:hover { background: var(--out-hover); border-color: var(--out-hover); }
.status-btn.out-btn.is-current {
  box-shadow: 0 0 0 2px #fecaca;
}
.status-btn.tiny {
  font-size: 0.68rem;
  padding: 0.22rem 0.4rem;
  white-space: nowrap;
}
.status-btn.tiny:hover { background: #f1f5f9; }
.status-btn.tiny.is-current {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.status-matrix {
  display: none;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
}
/* Only when the whole listing row is hovered — not OUT-button hover alone */
tr[data-id]:hover .status-matrix {
  display: flex;
}
.status-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.25rem;
}
.current-pill {
  font-size: 0.72rem;
  color: var(--muted);
  background: #f1f5f9;
  border-radius: 999px;
  padding: 0.15rem 0.45rem;
}
tr.row-leaving {
  opacity: 0;
  transition: opacity 0.18s ease;
}

.gallery {
  position: relative;
  display: inline-block;
  user-select: none;
  -webkit-user-select: none;
}
.gallery-thumb-link {
  display: inline-block;
  line-height: 0;
}
.gallery-thumb,
.col-img img.gallery-thumb {
  width: 192px;
  height: 144px;
  object-fit: cover;
  border-radius: 8px;
  background: #e5e7eb;
}
.gallery-count {
  position: absolute;
  right: 6px;
  bottom: 6px;
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  pointer-events: none;
  z-index: 2;
}
.gallery.gallery-loading .gallery-count {
  opacity: 0.8;
}
.gallery-preview {
  display: none;
  position: fixed;
  z-index: 1000;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.22);
  cursor: ew-resize;
  max-width: calc(500px + 16px);
  pointer-events: auto;
}
.gallery.is-preview-open .gallery-preview {
  display: block;
}
.col-img .gallery-preview-img,
.gallery-preview-img {
  display: block;
  width: auto !important;
  height: auto !important;
  max-width: 500px !important;
  max-height: 70vh !important;
  object-fit: contain !important;
  border-radius: 6px;
  background: #f1f5f9;
  pointer-events: none;
}
.gallery-preview-count {
  position: absolute;
  right: 14px;
  bottom: 28px;
  background: rgba(15, 23, 42, 0.75);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  pointer-events: none;
}
.gallery-preview-hint {
  display: block;
  margin-top: 6px;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}
