:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #e3e6ea;
  --text: #16181d;
  --muted: #6b7280;
  --accent: #1d4ed8;
  --accent-soft: #eff4ff;
  --ok: #15803d;
  --ok-soft: #eefbf2;
  --warn: #b45309;
  --warn-soft: #fef6e7;
  --err: #b91c1c;
  --err-soft: #fdeced;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a21;
    --border: #262b35;
    --text: #e7e9ee;
    --muted: #9aa3b2;
    --accent: #6395ff;
    --accent-soft: #16213c;
    --ok: #4ade80; --ok-soft: #10241a;
    --warn: #fbbf24; --warn-soft: #2a2113;
    --err: #f87171; --err-soft: #2b1618;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
a { color: var(--accent); }

/* ------------------------------------------------------------ login */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.login-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 32px; width: min(380px, 100%);
  box-shadow: var(--shadow); display: grid; gap: 14px;
}
.login-logo { font-size: 38px; text-align: center; }
.login-card h1 { margin: 0; font-size: 22px; text-align: center; }
.login-card > p { margin: -8px 0 8px; text-align: center; font-size: 14px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }

input[type=text], input[type=email], input[type=password], input[type=search] {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit; font-size: 14px;
  width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.error {
  background: var(--err-soft); color: var(--err); padding: 9px 11px;
  border-radius: 8px; font-size: 13px;
}

/* ----------------------------------------------------------- topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; }
.brand em { font-style: normal; color: var(--muted); font-weight: 500; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab {
  border: 0; background: none; color: var(--muted); font: inherit;
  font-size: 14px; padding: 7px 13px; border-radius: 8px; cursor: pointer;
}
.tab:hover { background: var(--bg); }
.tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user { font-size: 13px; color: var(--muted); }
.badge {
  display: inline-block; min-width: 18px; padding: 1px 6px; margin-left: 4px;
  background: var(--accent); color: #fff; border-radius: 9px;
  font-size: 11px; font-weight: 700; text-align: center;
}

/* ---------------------------------------------------------- buttons */
.btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  font: inherit; font-size: 14px; padding: 8px 14px; border-radius: 8px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
.btn.small { padding: 6px 11px; font-size: 13px; }
.btn.ghost { background: none; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn {
  border: 0; background: none; cursor: pointer; font-size: 16px;
  padding: 3px 5px; border-radius: 6px; line-height: 1; opacity: .55;
}
.icon-btn:hover { opacity: 1; background: var(--bg); }
.icon-btn.on { opacity: 1; }

/* ------------------------------------------------------------ layout */
.tab-panel { padding: 20px; max-width: 1240px; margin: 0 auto; }
.section-head { margin-bottom: 14px; }
.section-head h2, .panel h2 { margin: 0 0 4px; font-size: 17px; }
.section-head p { margin: 0; font-size: 13px; }
.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.grid-2 {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}
.row { display: flex; align-items: center; flex-wrap: wrap; }
.row.gap { gap: 8px; margin-top: 12px; }

/* ------------------------------------------------------------- stats */
.stats {
  display: grid; gap: 12px; margin-bottom: 18px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}
.stat {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px; box-shadow: var(--shadow);
}
.stat .n { font-size: 24px; font-weight: 700; line-height: 1.15; }
.stat .l { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ----------------------------------------------------------- toolbar */
.toolbar {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  margin-bottom: 14px;
}
.segmented {
  display: flex; background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
}
.segmented button {
  border: 0; background: none; color: var(--muted); font: inherit;
  font-size: 13px; padding: 7px 12px; cursor: pointer;
  border-right: 1px solid var(--border);
}
.segmented button:last-child { border-right: 0; }
.segmented button.active { background: var(--accent); color: #fff; font-weight: 600; }
.check { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
#search { max-width: 220px; margin-left: auto; }

/* ------------------------------------------------------------- cards */
.cards {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden;
}
.card.gone { opacity: .55; }
.card-img { height: 140px; background: var(--bg) center/cover no-repeat; }
.card-body { padding: 14px; display: grid; gap: 8px; }
.card-title {
  font-weight: 650; font-size: 15px; line-height: 1.35;
  display: flex; justify-content: space-between; gap: 8px; align-items: start;
}
.card-title a { color: inherit; text-decoration: none; }
.card-title a:hover { color: var(--accent); }
.card-actions { display: flex; gap: 2px; flex-shrink: 0; }
.facts { display: flex; flex-wrap: wrap; gap: 6px; }
.fact {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 2px 8px; font-size: 12.5px;
}
.fact.price { font-weight: 650; color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.addr { font-size: 13px; color: var(--muted); }
.summary {
  font-size: 13px; font-style: italic; color: var(--muted);
  border-left: 2px solid var(--border); padding-left: 9px;
}
.card-foot {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; font-size: 11.5px; color: var(--muted);
  padding: 9px 14px; border-top: 1px solid var(--border); margin-top: auto;
}
.pill {
  padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600;
}
.pill.k6 { background: var(--ok-soft); color: var(--ok); }
.pill.k7 { background: var(--accent-soft); color: var(--accent); }
.pill.reject { background: var(--warn-soft); color: var(--warn); }
.pill.new { background: var(--err-soft); color: var(--err); }
.pill.llm { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

/* verification verdict */
.pill.v-ok { background: var(--ok-soft); color: var(--ok); }
.pill.v-warn { background: var(--warn-soft); color: var(--warn); }
.pill.v-reject { background: var(--err-soft); color: var(--err); }
.pill.v-skip,
.pill.v-none { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

.verify-note {
  font-size: 12.5px; line-height: 1.45; border-radius: 6px; padding: 6px 9px;
  background: var(--warn-soft); color: var(--warn);
}
.verify-note.reject { background: var(--err-soft); color: var(--err); }
.verify-note.ok { background: var(--bg); color: var(--muted); }

/* A rejected listing is kept visible but visibly demoted. */
.card.vetoed { opacity: .72; }
.card.vetoed .card-img { filter: grayscale(1); }

.icon-btn.busy { animation: spin 1.1s linear infinite; opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty {
  text-align: center; padding: 50px 20px; color: var(--muted);
  background: var(--panel); border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ----------------------------------------------------------- sources */
.source-list { display: grid; gap: 10px; }
.source {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px; box-shadow: var(--shadow);
  display: grid; grid-template-columns: 10px 1fr auto; gap: 12px; align-items: center;
}
.source.disabled { opacity: .6; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.error { background: var(--err); }
.dot.running { background: var(--accent); animation: pulse 1.2s infinite; }
.dot.idle { background: var(--muted); }
@keyframes pulse { 50% { opacity: .3; } }
.source-name { font-weight: 600; font-size: 14.5px; }
.source-meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.source-note { font-size: 12px; color: var(--warn); margin-top: 3px; }
.source-actions { display: flex; gap: 6px; align-items: center; }

/* ------------------------------------------------------------ system */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.out {
  margin-top: 10px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px; font-size: 12.5px; white-space: pre-wrap;
  word-break: break-word; max-height: 260px; overflow: auto;
}
.events { display: grid; gap: 3px; max-height: 380px; overflow: auto; font-size: 12.5px; }
.event { display: grid; grid-template-columns: 130px 90px 1fr; gap: 10px; padding: 3px 0; }
.event time { color: var(--muted); font-variant-numeric: tabular-nums; }
.event .scope { color: var(--muted); }
.event.error .msg { color: var(--err); }
.event.warn .msg { color: var(--warn); }
.event.hit .msg { color: var(--ok); font-weight: 600; }

/* ------------------------------------------------------------- toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 11px 18px;
  border-radius: 8px; font-size: 14px; z-index: 60; box-shadow: var(--shadow);
}

@media (max-width: 720px) {
  .topbar { gap: 10px; }
  .tabs { margin-left: 0; order: 3; width: 100%; }
  .topbar-right { margin-left: auto; }
  .event { grid-template-columns: 1fr; gap: 0; }
}
