@font-face {
  font-family: "Space Grotesk";
  src: url("/static/fonts/space-grotesk-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #0f1420;
  --panel: #182031;
  --panel-2: #1f2a40;
  --border: #2b3a4f;
  --text: #e8edf5;
  --muted: #93a1b8;
  --accent: #4f8cff;
  --accent-2: #3670d6;
  --green: #34c07c;
  --red: #e05656;
  --amber: #e0a83a;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-family: "Space Grotesk", "Segoe UI", sans-serif; font-size: 1.3rem; font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: 10px; }
.brand img { width: 28px; height: 28px; display: block; }
.env-badge {
  font-family: "Segoe UI", sans-serif;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  background: var(--amber);
  color: #1a1a1a;
  padding: 2px 7px;
  border-radius: 999px;
  margin-left: 2px;
}
.header-right { display: flex; align-items: center; gap: 16px; }
.status { color: var(--muted); font-size: 0.85rem; }
.status .dot { color: var(--green); }
.user-area { display: flex; align-items: center; gap: 10px; }
.user-email { color: var(--muted); font-size: 0.85rem; }
.btn.small { padding: 5px 12px; font-size: 0.78rem; }

/* ---- auth ---- */
.auth-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  padding: 8vh 20px 60px;
  min-height: calc(100vh - 61px);
  overflow: hidden;
}
.auth-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.28;
  pointer-events: none;
}
.auth-blob.one {
  width: 440px; height: 440px; background: #2b5cc7;
  top: -140px; left: max(-120px, calc(50% - 620px));
  animation: authdrift 16s ease-in-out infinite alternate;
}
.auth-blob.two {
  width: 400px; height: 400px; background: #1c8a63;
  bottom: -160px; right: max(-100px, calc(50% - 600px));
  animation: authdrift 19s ease-in-out infinite alternate-reverse;
}
@keyframes authdrift {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(50px, 35px) scale(1.12); }
}
.auth-panel {
  position: relative;
  width: 100%;
  max-width: 420px;
  height: fit-content;
  background: rgba(24, 32, 49, 0.88);
  backdrop-filter: blur(8px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  animation: authrise 0.45s ease both;
}
.auth-panel::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, #5a95ff, #34c07c);
}
@keyframes authrise {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: none; }
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.auth-brand img { width: 46px; height: 46px; }
.auth-brand h1 { margin: 0; font-family: "Space Grotesk", "Segoe UI", sans-serif; font-size: 1.6rem; letter-spacing: -0.015em; }
@media (prefers-reduced-motion: reduce) {
  .auth-blob, .auth-panel { animation: none !important; }
}
.auth-panel form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.auth-panel label { display: flex; flex-direction: column; gap: 5px; font-size: 0.82rem; color: var(--muted); }
/* checkbox rows sit inline, not stacked like the field labels above */
.auth-panel label.check { flex-direction: row; align-items: center; gap: 8px; cursor: pointer; }
.auth-panel label.check input { width: auto; padding: 0; margin: 0; flex: none; }
.auth-panel input { background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 7px; padding: 10px 11px; font-size: 0.95rem; }
.auth-panel input:focus { outline: none; border-color: var(--accent); }
.auth-error { color: var(--red); font-size: 0.85rem; }
.auth-ok { color: var(--green); font-size: 0.85rem; }
.auth-link { display: block; margin-top: 14px; color: var(--muted); font-size: 0.82rem; }
.auth-link:hover { color: var(--accent); }

.name-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.pw-checks {
  list-style: none;
  margin: 0;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.pw-checks li::before {
  content: "○";
  display: inline-block;
  width: 1.4em;
  color: var(--muted);
}
.pw-checks li.ok { color: var(--text); }
.pw-checks li.ok::before { content: "✓"; color: var(--green); }

.qr-box {
  background: #fff;
  border-radius: 10px;
  padding: 14px;
  width: fit-content;
  margin: 14px auto;
}
.qr-box img { display: block; width: 210px; height: 210px; }
.muted.small { font-size: 0.78rem; }
.muted.small code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 6px;
  word-break: break-all;
}
.recovery-codes {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 18px;
  font-size: 1rem;
  line-height: 1.7;
  letter-spacing: 0.06em;
  columns: 2;
}
#twofa-setup form, #twofa-email-setup form, #twofa-verify { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
#twofa-setup label, #twofa-email-setup label, #twofa-verify label { display: flex; flex-direction: column; gap: 5px; font-size: 0.82rem; color: var(--muted); }
#twofa-setup input, #twofa-email-setup input, #twofa-verify input { background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 7px; padding: 10px 11px; font-size: 1.05rem; letter-spacing: 0.15em; }

.verify-banner {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  background: rgba(224, 168, 58, 0.12);
  border-bottom: 1px solid var(--amber);
  color: var(--text);
  padding: 10px 22px;
  font-size: 0.88rem;
}

.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 18px;
  padding: 18px 22px;
  max-width: 1500px;
  margin: 0 auto;
}
/* Grid items default to min-width:auto, so a wide child (e.g. the admin tables)
   would stretch the column past the viewport and scroll the whole page. Let the
   sidebar/main shrink instead, so inner .admin-table-wrap containers scroll. */
.layout > * { min-width: 0; }

/* ---- sidebar ---- */
.sidebar { display: flex; flex-direction: column; gap: 12px; }

.search-list { display: flex; flex-direction: column; gap: 8px; }

.search-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.search-item:hover { border-color: var(--accent); }
.search-item.selected { border-color: var(--accent); background: var(--panel-2); }
.search-item .name { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.search-item .desc { color: var(--muted); font-size: 0.8rem; margin-top: 4px; }
.search-item .counts { color: var(--muted); font-size: 0.78rem; margin-top: 6px; }
.search-item.paused { opacity: 0.55; }

.badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}
.badge.new { background: var(--green); }

/* ---- panels ---- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.85rem; }

/* ---- form ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px 16px;
}
.grid label { display: flex; flex-direction: column; gap: 5px; font-size: 0.82rem; color: var(--muted); }
.grid .field { display: flex; flex-direction: column; gap: 5px; }
.grid .field-label { font-size: 0.82rem; color: var(--muted); }
.grid .span2 { grid-column: span 2; }

/* ---- multi-select dropdown (colours) ---- */
.ms { position: relative; }
.ms-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 9px 10px;
  font-size: 0.9rem;
  cursor: pointer;
  text-align: left;
}
.ms-toggle:focus { outline: none; border-color: var(--accent); }
.ms-toggle::after {
  content: "";
  flex: 0 0 auto;
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--muted);
}
#colour-summary {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ms-toggle.is-empty #colour-summary { color: var(--muted); }
.ms-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  z-index: 30;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px 12px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
  max-height: 260px;
  overflow-y: auto;
}
.ms-clear {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 0;
}
.ms-clear:hover { text-decoration: underline; }
.ms-options { display: flex; flex-direction: column; gap: 9px; margin-top: 10px; }
.ms-options label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 9px;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
}
.ms-options input[type="checkbox"] { flex: 0 0 auto; }

input[type="text"], input[type="number"], select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 9px 10px;
  font-size: 0.9rem;
  width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
select:disabled { opacity: 0.5; }

.sources { border: 1px solid var(--border); border-radius: var(--radius); margin-top: 18px; padding: 12px 16px 16px; }
.sources legend { color: var(--muted); font-size: 0.82rem; padding: 0 6px; }
.sources .src-group + .src-group { margin-top: 14px; }
.sources .src-group-title { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.sources .src-row { display: flex; flex-wrap: wrap; gap: 10px 22px; }
.sources label { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; font-size: 0.9rem; }
.sources label.irrelevant { opacity: 0.4; cursor: not-allowed; }
.sources .src-note { display: block; color: var(--muted); font-size: 0.75rem; }

.form-actions { margin-top: 20px; display: flex; gap: 10px; }

/* ---- buttons ---- */
.btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn:hover { background: var(--border); }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--red); border-color: var(--red); background: transparent; }
.btn.danger:hover { background: rgba(224, 86, 86, 0.12); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: wait; }

/* ---- results ---- */
.results-header { display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap; align-items: flex-start; }
.results-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.results-actions select { width: auto; }
.check { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--muted); white-space: nowrap; }

.run-info { margin: 12px 0 4px; font-size: 0.8rem; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.run-info .err { color: var(--amber); }
.run-info .err-detail {
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.72rem;
  margin: 2px 0 4px 18px;
}

.listings {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: border-color 0.15s;
}
.card:hover { border-color: var(--accent); }
.card.inactive { opacity: 0.55; }

.card .img {
  aspect-ratio: 4 / 3;
  background: #0a0e16;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 2rem;
  overflow: hidden;
}
.card .img img { width: 100%; height: 100%; object-fit: cover; }
/* eBay: show the whole photo (letterboxed) instead of cropping to fill */
.card .img.fit-contain img { object-fit: contain; }

.card .flags { position: absolute; top: 8px; left: 8px; display: flex; gap: 6px; }
.flag { font-size: 0.7rem; font-weight: 700; padding: 3px 8px; border-radius: 6px; color: #fff; }
.flag.new { background: var(--green); }
.flag.drop { background: var(--amber); color: #1a1a1a; }
.flag.gone { background: var(--red); }
.flag.writeoff { background: #b5462f; letter-spacing: 0.02em; }

.card .body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card .title { font-weight: 600; font-size: 0.92rem; line-height: 1.3; }
.card .title a { color: var(--text); text-decoration: none; }
.card .title a:hover { color: var(--accent); }
.card .price { font-size: 1.15rem; font-weight: 700; color: var(--accent); }
.card .price .was { color: var(--muted); font-size: 0.8rem; font-weight: 400; text-decoration: line-through; margin-left: 6px; }
.card .specs { color: var(--muted); font-size: 0.8rem; }
.card .foot {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 0.74rem;
  padding-top: 8px;
}
.src-pill { border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px; font-size: 0.72rem; }

.empty { color: var(--muted); padding: 30px 0; text-align: center; grid-column: 1 / -1; }

/* ---- admin dashboard ---- */
#admin-panel h3 { margin: 26px 0 10px; font-size: 0.95rem; }
.admin-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 18px;
}
.admin-stat {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: center;
}
.admin-stat .v { font-size: 1.4rem; font-weight: 700; }
.admin-stat .l { color: var(--muted); font-size: 0.75rem; margin-top: 3px; }

.admin-table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.admin-table th {
  text-align: left; color: var(--muted); font-weight: 600;
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 7px 10px; border-bottom: 1px solid var(--border);
}
.admin-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.admin-table .good { color: var(--green); }
.admin-table .bad { color: var(--red); }
.admin-actions { white-space: nowrap; text-align: right; }
.admin-table th.actions-col { text-align: right; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.btn.small.danger { color: var(--red); border-color: var(--red); background: transparent; }

.admin-errors { display: flex; flex-direction: column; gap: 8px; font-size: 0.85rem; }
.admin-error .err-detail { margin-left: 0; }
#admin-panel .err-detail {
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.72rem;
  margin-top: 2px;
  word-break: break-word;
}

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(2, 1fr); }
}

/* Narrow viewports: the top bar is a single non-wrapping row on desktop, which
   cramps once it can't fit (~700px). Stack it into full-width rows — brand, then
   the status line, then the account row — so nothing is squeezed into a half
   column (which made the status wrap to 3 lines and "Log out" break in two). */
@media (max-width: 700px) {
  header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 14px;
  }
  .brand { font-size: 1.15rem; gap: 8px; }
  .brand img { width: 24px; height: 24px; }
  .header-right {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .status { font-size: 0.8rem; }
  .user-area { justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
  .user-email { margin-right: auto; align-self: center; word-break: break-word; }
  .btn.small { white-space: nowrap; }
}
